Snake Game Tutorial 14a
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Snake Game Tutorial 14a
Lol, cheers
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Snake Game Tutorial 14a
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: whereas my Snake.h file had: 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!
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:
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:missing type specifier - int assumed.
Code: Select all
#include "Board.h"
Code: Select all
#include "Board.h"
#include "Location.h"
#include "Colors.h"
#include "Food.h"
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!
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Snake Game Tutorial 14a
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.
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.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Snake Game Tutorial 14a
That makes so much sense. Thank you very much!
Re: Snake Game Tutorial 14a
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?
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?
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Snake Game Tutorial 14a
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 ).
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Snake Game Tutorial 14a
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.
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
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.
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Snake Game Tutorial 14a
Hey, glad you found the problem, good luck.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Snake Game Tutorial 14a
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?
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?