Page 6 of 7

Re: Snake Game Tutorial 14a

Posted: August 31st, 2017, 1:54 am
by albinopapa
Lol, cheers

Re: Snake Game Tutorial 14a

Posted: January 6th, 2018, 6:17 pm
by jresch95
After spending a couple of hours struggling with errors, I decided to post to this thread to request assistance. Just after resolving to do so, I fixed my problem, so I thought I would post anyways in case someone else was having the same issue.

While working through tutorial 14b, I finally got the goal class defined and implemented, but upon building, I was met with several errors pointing to goal.h and stating:
missing type specifier - int assumed.
I checked and rechecked that all was correct in the goal.h, then turned to Google where I discovered from the following stack overflow post (https://stackoverflow.com/questions/232 ... nt-assumed) that the error is a result of something called circular dependency. This pointed me towards my various #include tags. After scouring the tutorial video and combing through the .h files, I realized that Chili's Snake.h file only had:

Code: Select all

#include "Board.h"
whereas my Snake.h file had:

Code: Select all

#include "Board.h"
#include "Location.h"
#include "Colors.h"
#include "Food.h"
The extra included header files were probably leftover from my efforts to figure out the snek game myself. Removing the extras immediately fixed all the errors.

I hope this helps anyone who may have struggled with this too. For those reading this who are more knowledgeable than I am, would you clarify why simply including unnecessary .h files causes the program to break? Furthermore, why does Chili only include Location.h in Board.h despite having location data members in many other header files? It makes sense to me that a header file should know about Location.h if they are going to have location objects. Or is it that they DO know about Location.h because all of them are included in Game.h? Thank you for your help!

Re: Snake Game Tutorial 14a

Posted: January 6th, 2018, 9:27 pm
by albinopapa
The header files are copy pasted everywhere they are included, and it is recursive. If Board.h includes Location.h, then any file that includes Board.h knows about the Location class. Which means Location.h is copied and pasted to Board.h and then Board.h is pasted to Snek.h with the Location.h contents. All of that is copied to the Snek.cpp file so that you can use the Location class and Board class inside Snek.

This should help figure out why circular dependencies wreck your program. If you include Snek.h in Food.h and Food.h in Snek.h, when does the compiler know when to quit making copies of each? Granted, the #pragma once should stop this behavior, but it doesn't.

Re: Snake Game Tutorial 14a

Posted: January 7th, 2018, 5:43 am
by jresch95
That makes so much sense. Thank you very much!

Re: Snake Game Tutorial 14a

Posted: August 15th, 2018, 6:48 pm
by ArmSun
Hi
I'm trying to run snek game, and I'm getting an error at the disco part )
When I try to make a constructor for Board class, it gives an error
Graphics::Graphics(Graphics &) attempting to reference a deleted function

and the error line is
gfx(gfx)

I've looked into Graphics.h and found function declaration like this
Graphics( const Graphics& ) = delete;

Can anyone help me to move forward?

Re: Snake Game Tutorial 14a

Posted: August 16th, 2018, 2:49 am
by albinopapa
More than likely, you are trying to pass the gfx object by value. This would be a function like: Board::Draw( Graphics gfx ). You don't want a copy of the Graphics object gfx, you want a reference to the Graphics object: Board::Draw( Graphics& gfx ).

Re: Snake Game Tutorial 14a

Posted: August 16th, 2018, 6:07 pm
by ArmSun
This is the declaration of the function
Board(Graphics& gfx);

And here is it's definition

Board::Board(Graphics& gfx)
:
gfx(gfx)
{
}

Seems like I'm passing gfx by reference, not by value.

Re: Snake Game Tutorial 14a

Posted: August 16th, 2018, 7:58 pm
by ArmSun
Thank you for the reply. I've just found the error. I was declaring the constructor function in the right way, but the gxf parameter was not a reference, and that was causing the issue.

Re: Snake Game Tutorial 14a

Posted: August 16th, 2018, 11:19 pm
by albinopapa
Hey, glad you found the problem, good luck.

Re: Snake Game Tutorial 14a

Posted: October 2nd, 2018, 6:50 pm
by ArmSun
Hi everyone, it's me again )

I'm having trouble with running snek game code. From time to time it gives me OUT OF VIDEO MEMORY error. I thought that I have done something wrong, so I've downloaded Chili's code from git. It gives the same error.

Can anyone help me?