idiot 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
Beshr
Posts: 36
Joined: Mon Mar 12, 2007 3:34 pm
Location: Damascus, Syria

idiot question :)

Post by Beshr »

hey all!
i know this is an idiot question, How can i clear the scene to start a new level in my game?

:oops: :oops:
(\__/)
(='.'=) Copy bunny into your signature to
(")_(") help him gain world domination.
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

Scene->clear() clears the scene.
If you don't have anything nice to say, don't say anything at all.
Beshr
Posts: 36
Joined: Mon Mar 12, 2007 3:34 pm
Location: Damascus, Syria

answer

Post by Beshr »

thx! but that's not what i ment

in c++, how can i set up the project so i can for example make a cpp file for each leve, i'm not a good c++ programmer, is there is any place for tutorials on this subject??
(\__/)
(='.'=) Copy bunny into your signature to
(")_(") help him gain world domination.
Dr.Bunshin
Posts: 34
Joined: Sat Mar 31, 2007 8:38 pm

Re: answer

Post by Dr.Bunshin »

Beshr wrote:thx! but that's not what i ment

in c++, how can i set up the project so i can for example make a cpp file for each leve, i'm not a good c++ programmer, is there is any place for tutorials on this subject??
Hey Beshr

In actuality, you can just make functions for each level, and of course put those functions in the said cpp files. The viability of this depends on what kind of game you are making. What kind of game are you making?
Beshr
Posts: 36
Joined: Mon Mar 12, 2007 3:34 pm
Location: Damascus, Syria

answer

Post by Beshr »

my game is about a ball that i need to move to take to some place. it's not about actully the type of the game i think. my point is when i make another funtion let's say for level 2, when i call it it tell me this:

Code: Select all

Linking...
Game_initialize.obj : error LNK2005: "class irr::video::IVideoDriver * driver" (?driver@@3PAVIVideoDriver@video@irr@@A) already defined in Game.obj
Game_initialize.obj : error LNK2005: "class irr::newton::World * p_world" (?p_world@@3PAVWorld@newton@irr@@A) already defined in Game.obj
Game_initialize.obj : error LNK2005: "class irr::scene::ISceneManager * smgr" (?smgr@@3PAVISceneManager@scene@irr@@A) already defined in Game.obj
i know that this is because i have them already defined, but if i didn't define them, it tells me that it's an undeclared identifier.
:idea: :?: :idea: :?:
(\__/)
(='.'=) Copy bunny into your signature to
(")_(") help him gain world domination.
jam
Posts: 409
Joined: Fri Nov 04, 2005 3:52 am

Re: answer

Post by jam »

Beshr wrote: in c++, how can i set up the project so i can for example make a cpp file for each leve, i'm not a good c++ programmer, is there is any place for tutorials on this subject??
You might give Irrwizard a look. It will give you a basic framework to start off with.
system-independent, adj.:
Works equally poorly on all systems.
-- unknown
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Don't define variables in .h files, but only in .cpp (and thus later on in .o) files. Because every inclusion of the .h file will create another instance of the variable, with the same name and scope.
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

i thought this prevents creating another instances of variables

Code: Select all

#ifndef _h_file_
#define _h_file_

<...some code...>

#endif
eneru
Posts: 40
Joined: Tue Apr 10, 2007 8:38 am

Post by eneru »

hybrid wrote:Don't define variables in .h files, but only in .cpp (and thus later on in .o) files. Because every inclusion of the .h file will create another instance of the variable, with the same name and scope.
what ? the variable are supposed to be defined in the .h along with the functions (unless you want to "hide" them), arn't they ?
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

actually headers are ment to be class definition files so variables should be defined in class
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

if headers are ment to be class definition files, how come headers are used with plain c too? ;)
headers are declaration files, but general, not restricted to classes.


Back to the subject, the problem is that if you declare a variable in a cpp-file, the compiler assigns a name to the space where the variable will be in your program, so that it can be refered to using that name. (sortof). If you have another variable of the same name in another cpp file, it will get the same name. So far so good.
But when the linker kicks in, the problem arise, because there are 2 memory areas with the same name. (sortof).
The solution is to define your variable in a way that doesn't make the compiler assign the name a new memory area, but instead just use the name, and let the linker do the linking between name and memory area.(sortof).

example:

Code: Select all

//File1.cpp
int x; //Global int x


//File2.cpp
int x; //global int x

//This produces that error, since there are 2 global "x"-objects

Code: Select all

//File1.cpp
int x; //Global int x

//File2.cpp
extern int x; //Global in x, which's object/memory is in another .cpp
EDIT: Hehe, i messed up here. The variables need to be extern in .h-files too.

Code: Select all

//file1.cpp
#include "File3.h"
int x;

//File 2.cpp
#include "File3.h"
//X was declared in file3.h

//File3.h
#ifndef _h_file_    //Protection!
#define _h_file_
extern int x;
#endif
sortof.

As i've understood it, definitions are the actual code or variable-objects, while declarations are maps to how we use the code/objects. sortof.
So multiple definitions is a problem, but multiple declarations should not be a problem.

Hope it helps a little
Last edited by Luben on Tue Apr 10, 2007 5:26 pm, edited 2 times in total.
If you don't have anything nice to say, don't say anything at all.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

eneru wrote:
hybrid wrote:Don't define variables in .h files, but only in .cpp (and thus later on in .o) files. Because every inclusion of the .h file will create another instance of the variable, with the same name and scope.
what ? the variable are supposed to be defined in the .h along with the functions (unless you want to "hide" them), arn't they ?
They should be declared in .h files, but not defined. Even header protections won't help with definitions, as these will be put into each .o files which includes the .h file.
Post Reply