very newb question

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
Kamazy
Posts: 24
Joined: Tue Oct 11, 2005 12:16 pm

very newb question

Post by Kamazy »

OK, here waht i want to do.
i wana make driver,device.. and all those globals so i can use device-> in another file/function.
But i can't seem to understand how to "move" a variable from one file to the other or link 2 files variables.
i'm sure this is very newb question but noone of the tutorials cover that. :(

[forum request]
why not have a sticky "post minor questions here" thread so that newb questoins don't need a new thread everytime. :P
Cheerz! I'm new don't shoot! Image
Image
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

You can declare them as external, or simple pass the pointer to a function (maybe constructor)...

This is basic C/C++ knowledge, so I suggest you to learn the C/C++ basics !!!
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Kamazy
Posts: 24
Joined: Tue Oct 11, 2005 12:16 pm

Post by Kamazy »

would you mind gicing me an example of making device an external?
i tried a few times but couldn't get it to work. XD
Cheerz! I'm new don't shoot! Image
Image
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

If another class needs a pointer to the device then just pass it to that class through the constructor
Image Image Image
Kamazy
Posts: 24
Joined: Tue Oct 11, 2005 12:16 pm

Post by Kamazy »

Could anyone point me to a code example of how to make external variables?
I'm very newb to this kind of variable passing.
Cheerz! I'm new don't shoot! Image
Image
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

How about trying to google something like "c++ external variables"?
Image Image Image
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Well, this is basic knowledge, so you really shoul have a look for a C/C++ tutorial first...

anyways, here's a small example:

main.cpp

Code: Select all

#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

// this is the class you whant to use
#include "foo.h"
foo myClass;

IrrlichtDevice* device;
ISceneManager* smgr;

int main(){
  // here is the initialisation of the engine and main loop...
}
and this is the header file of the class:

foo.h

Code: Select all

#ifndef FOO_H_INCLUDED
#define FOO_H_INCLUDED

class foo{
  // here are the declarations of the class members located
};

extern IrrlichtDevice* device;
extern ISceneManager* smgr;

#endif // FOO_H_INCLUDED
Now you can use device and smgr as they where created inside the foo class...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
chaoslion
Posts: 25
Joined: Sun Oct 30, 2005 1:44 pm

Post by chaoslion »

yea or here:
put this in your global header file:

Code: Select all

extern irr::irrichtDevice *device;
and then in ONE .cpp file the declaration

Code: Select all

irr::irrichtDevice *device = NULL;
Post Reply