confusing no error problem

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
wizecoder
Posts: 13
Joined: Thu Jan 03, 2008 9:36 pm

confusing no error problem

Post by wizecoder »

I am trying to make a pong game but when i run this code there is a problem, there are no build or debug errors but when it starts to run there is just a window that sets the background to whatever is behind it, there is supposed to be a simple paddle on the screen. PLEASE HELP.
here is my code:

Code: Select all

//this program is to try and make a pong game using irrlicht
//include headers
#include <irrlicht.h>

//link to the irrlicht lib
#pragma comment (lib, "Irrlicht.lib")

//use the irrlicht namespace
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace gui;
using namespace io;

//variables
bool keys[irr::KEY_KEY_CODES_COUNT];


//structs and classes
class MyEventReceiver : public IEventReceiver {
public:
	virtual bool OnEvent(const SEvent& event) {
		if(event.EventType == irr::EET_KEY_INPUT_EVENT){
			keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
			return false;
		}
		return false;
	}
};

struct OBJECT
{
	s32 x, y;
	s32 h, w;
	f64 XMomentum, YMomentum;
	ITexture* tex;
};

IrrlichtDevice *device = createDevice(EDT_DIRECT3D9);
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
MyEventReceiver rv;

//functions
void Initialize(OBJECT *ob[]);
void Run(OBJECT *ob[]);


int main()
{
	//initialize
	void Initialize(OBJECT *ob[]);
	
	//game loop
	while(device->run() && driver)
	{
		void Run(OBJECT *ob[]);
	}
	device->drop();
	return 0;
}
void Initialize(OBJECT *ob[])
{

	//set the event receiver
	device->setEventReceiver(&rv);

	//set the window caption
	device->setWindowCaption(L"Pong with irrlicht");

	//load up the player 1 attributes
	ob[0]->tex = driver->getTexture("../../Media/Player1paddle.jpg");
	ob[0]->x = 300;
	ob[0]->y = 10;
	ob[0]->XMomentum = 0;
	ob[0]->YMomentum = 0;
	ob[0]->h = 16;
	ob[0]->w = 45;
}
void Run(OBJECT *ob[])
{
	//if the window is active
	if (device->isWindowActive())
	{
		//run the game
		u32 time = device->getTimer()->getTime();
		driver->beginScene(true, true, SColor(0, 120,102,136));
		driver->draw2DImage(ob[0]->tex, position2d<s32>(ob[0]->x,ob[0]->y));
		driver->endScene();
	}
};
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

wow, can anybody do more mistakes ??? :shock:

well, seriously, 1st you define 2 functions with a pointer to an array:

Code: Select all

void Initialize(OBJECT *ob[]);
void Run(OBJECT *ob[]); 
that's not what you want !!!
2nd you try to call this functions but you define them !?!?!
3rd you try to pass an array that doesn't exist to them !!!
well, to make it short, here is the corrected code, compare it to yours and find the differences (I marked the lines with // <<<<<<<)... ;)

Code: Select all

//this program is to try and make a pong game using irrlicht
//include headers
#include <irrlicht.h>

//link to the irrlicht lib
#pragma comment (lib, "Irrlicht.lib")

//use the irrlicht namespace
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace gui;
using namespace io;

//variables
bool keys[irr::KEY_KEY_CODES_COUNT];


//structs and classes
class MyEventReceiver : public IEventReceiver {
public:
   virtual bool OnEvent(const SEvent& event) {
      if(event.EventType == irr::EET_KEY_INPUT_EVENT){
         keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
         return false;
      }
      return false;
   }
};

struct OBJECT
{
   s32 x, y;
   s32 h, w;
   f64 XMomentum, YMomentum;
   ITexture* tex;
};

IrrlichtDevice *device = createDevice(EDT_DIRECT3D9);
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
MyEventReceiver rv;

//functions
void Initialize(OBJECT *ob); // <<<<<<<
void Run(OBJECT *ob); // <<<<<<<


int main()
{
  OBJECT ob[1]; // <<<<<<<
   //initialize
   Initialize(ob); // <<<<<<<

   //game loop
   while(device->run() && driver)
   {
      Run(ob); // <<<<<<<
   }
   device->drop();
   return 0;
}
void Initialize(OBJECT *ob) // <<<<<<<
{

   //set the event receiver
   device->setEventReceiver(&rv);

   //set the window caption
   device->setWindowCaption(L"Pong with irrlicht");

   //load up the player 1 attributes
   ob[0].tex = driver->getTexture("../../Media/Player1paddle.jpg"); // <<<<<<<
   ob[0].x = 300; // <<<<<<<
   ob[0].y = 10; // <<<<<<<
   ob[0].XMomentum = 0; // <<<<<<<
   ob[0].YMomentum = 0; // <<<<<<<
   ob[0].h = 16; // <<<<<<<
   ob[0].w = 45; // <<<<<<<
}
void Run(OBJECT *ob) // <<<<<<<
{
   //if the window is active
   if (device->isWindowActive())
   {
      //run the game
      u32 time = device->getTimer()->getTime();
      driver->beginScene(true, true, SColor(0, 120,102,136));
      driver->draw2DImage(ob[0].tex, position2d<s32>(ob[0].x,ob[0].y)); // <<<<<<<
      driver->endScene();
   }
};
Last edited by Acki on Tue Jan 15, 2008 1:19 am, edited 2 times in total.
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

can you tell me how are you running the program?

the reason could be the program could not find the path to the texture.

make sure the current directory of the main app is set to the right directory.
Image
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

dlangdev wrote:can you tell me how are you running the program?

the reason could be the program could not find the path to the texture.

make sure the current directory of the main app is set to the right directory.
no, the problem is with the code itself... ;)
but I also wonder that it runs, I never thought this could work, but it runs without error messages (but doesn work of course)... :shock:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

Code: Select all

int main() 
{ 
   //initialize 
   void Initialize(OBJECT *ob[]); 
    
   //game loop 
   while(device->run() && driver) 
   { 
      void Run(OBJECT *ob[]); 
   } 
   device->drop(); 
   return 0; 
} 

Code: Select all

void Initialize(OBJECT *ob[]); 
yeah, i thought about that too, but decided not to call because the poster might have elided it.

maybe he's using visual studio 2020?

that could explain why there were no build errors.

oh my god! this poster is from the future!
Last edited by dlangdev on Tue Jan 15, 2008 1:27 am, edited 2 times in total.
Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Re: confusing no error problem

Post by rogerborg »

wizecoder wrote:there are no build or debug errors
Yerrrrs, and it's only a scratch.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

dlangdev wrote: maybe he's using visual studio 2020?

that could explain why there were no build errors.
maybe he does use it, but it also compiles for me with Code::Blocks (MinGW/GCC) without any errors or warnings and shows the same symptoms he discribed...

@rogerborg: YEAH, GREAT, I love Monty Python !!! :lol:
!!! let's call it a draw !!!
Brian wrote: Life's a piece of shi*,
When you look at it.
Life's a laugh and death's a joke it's true.
You'll see it's all a show.
Keep 'em laughing as you go.
Just remember that the last laugh is on you.
And...
"Always look on the bright side of life !!!"
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

acki: see i told ya, he's a spy from the future.
Image
wizecoder
Posts: 13
Joined: Thu Jan 03, 2008 9:36 pm

Post by wizecoder »

Wow thanks acki it works and sorry for the noob mistakes i am trying to learn. :cry:
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

good to know you got it working.

keep moving forward, figure out where u got it wrong and go to the next.

see ya later.
Image
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

wizecoder wrote:Wow thanks acki it works and sorry for the noob mistakes i am trying to learn. :cry:
no problem ;)
at least you tried something on your own and in this case you're always welcome... :lol:
but I also suggest you to read a C/C++ book or search the web for tutorials about C/C++... ;)
dlangdev wrote:acki: see i told ya, he's a spy from the future.
yes, I read it, but I don't get the reason why he's from the future ??? :shock:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Acki wrote:
dlangdev wrote:acki: see i told ya, he's a spy from the future.
yes, I read it, but I don't get the reason why he's from the future ??? :shock:
I think we both assumed that the original code wouldn't compile, when actually (to my surprise) it does.

So, wizecoder, I offer you a contrite apology for doubting you. It's really quite an interesting thing you did.

Code: Select all

int main()
{
   //initialize
   void Initialize(OBJECT *ob[]);
   
   //game loop
   while(device->run() && driver)
   {
      void Run(OBJECT *ob[]);
   }
   device->drop();
   return 0;
}
What you'd managed to do there is that rather than calling Initialize() and Run(), you declared their existence locally within the scope of the main() function. A local function declaration is a rather unusual but perfectly valid thing to do. Since the local declarations don't contradict the global declarations, the compiler was quite happy with it, which illustrates that it knows more than me. ;)

It didn't do what you expected, but it's very interesting code, so thanks for waking me up and making me think.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply