[SOLVED] Creating IGUIEnvironment object, what abut id ??

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
WhyMe
Posts: 10
Joined: Sat Jan 26, 2013 5:31 pm

[SOLVED] Creating IGUIEnvironment object, what abut id ??

Post by WhyMe »

Hello.
I have not idea how and where to find explaint abut "id" number in function, like addbutton(...).
The default number of id is -1. Why ??
What is happen, when I set id = -1,0, > 1 or < -1 ??

I have hope, I wrote it clearly.
Regards.
Last edited by WhyMe on Tue Feb 12, 2013 10:04 pm, edited 1 time in total.
chronologicaldot
Competition winner
Posts: 688
Joined: Mon Sep 10, 2012 8:51 am

Re: Creating IGUIEnvironment object, what abut id ??

Post by chronologicaldot »

An ID is what you can use to find your GUI elements without having a direct pointer to them. For example, in general, programs add their GUI elements to the GUI environment's root GUI element, which you can get via the following:

Code: Select all

 
IrrlichtDevice* device = createDevice();
device->getGUIEnvironment()->getRootGUIElement();
 
Once you have a pointer to a GUI element (such as the root GUI element), you can find it based on it's given ID via the function virtual IGUIElement * getElementFromId (s32 id, bool searchchildren=false) const.
The function returns a pointer to the first GUI element found with that ID.
NOTE: The only GUI elements that are searched are the GUI element itself (on which you called the function) and its children. In order to search the children (child GUI elements) of the children (child GUI elements), you must pass a "true" as the second parameter to this function.

The fact that the ID is set to -1 by default means nothing. It's convenient as a programmer to say -1 means "no ID". You could use it as an ID if you wanted.
DO NOT use 0 as an ID (if you want to use getElementFromId() that is) because it is reserved for the root GUI element.

Hope that helps.
WhyMe
Posts: 10
Joined: Sat Jan 26, 2013 5:31 pm

Re: Creating IGUIEnvironment object, what abut id ??

Post by WhyMe »

Well, ok I understand how it was made.
So, the ID can be all digits in integer range (except 0).

Thank you for respond.
Post Reply