Need advices with scene switching

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
Is3dpic
Posts: 16
Joined: Mon Aug 25, 2008 6:12 pm

Need advices with scene switching

Post by Is3dpic »

Hello,

In my game, I have to login first, then choose a server to pay on ( like a mmo).
Ok, I login and here is my problem : I have to delete the buttons, edits box, background image and then create the interface for server choosing, but what's the best here ? resetting device ? dropping it and creating another one ? or keeping it (which I really want to do) delete images , gui etc and draw new one but in this case I don't really know what to do..

I hope I'm clear, my keyboard bugs so forgive my spelling mistakes

thanks you
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Re: Need advices with scene switching

Post by Acki »

Is3dpic wrote:or keeping it (which I really want to do) delete images , gui etc and draw new one but in this case I don't really know what to do..
if you wantto do it this way then do it this way (I probably also would)... ;)
and the API is a realy magical place to gather informations:
http://irrlicht.sourceforge.net/docu/cl ... t.html#a31
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Is3dpic
Posts: 16
Joined: Mon Aug 25, 2008 6:12 pm

Post by Is3dpic »

Wow, that what I call a beautiful function lol, going to make tests..thanks.
Is3dpic
Posts: 16
Joined: Mon Aug 25, 2008 6:12 pm

Post by Is3dpic »

Ok after severals tests, I came up with only errors...I don't know how to use this.

Example :

Code: Select all

	IGUIElement*	elem2 = loginPasswordBox;
	elem2->remove();
I get an error on that, I don't know how to use it, can someone light me up ? thanks xD
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I suggest you learn how to program in C++ :P

What you've done there is created a garbage pointer and then tried to delete it, which is highly inadvisable and will almost always result in your app crashing.

You need to assign a valid pointer to elem2 before even thinking about dereferencing it.
Image Image Image
Is3dpic
Posts: 16
Joined: Mon Aug 25, 2008 6:12 pm

Post by Is3dpic »

Code: Select all

IGUIElement* root = m_guienv->getRootGUIElement();
	root->getElementFromId(loginPasswordBox->getID(), false);
	root->remove();
Well, somehow I think I have almost it...tough this code doesn't delete the loginpasswordbox :P


Edit : Some progress so far ->

Code: Select all

	IGUIElement* root = m_guienv->getRootGUIElement();
	IGUIElement* e = root->getElementFromId(loginUsernameBox->getID(), true);
	if (e) e->remove(); 
It's does delete the button :P
Last edited by Is3dpic on Wed Oct 29, 2008 10:05 am, edited 1 time in total.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

You should look at the docs to figure out how to use IGUIElement::getElementFromId properly ;)

It returns a pointer to the element that you asked for (could be NULL though if it couldn't find it)

So you should do this:

Code: Select all

IGUIElement* root = m_guienv->getRootGUIElement(); 
IGUIElement* myElement = root->getElementFromId(loginPasswordBox->getID(), false); 
if (myElement) myElement->remove();
Image Image Image
Is3dpic
Posts: 16
Joined: Mon Aug 25, 2008 6:12 pm

Post by Is3dpic »

I found out this I just edited my post before you posted xP
thanks anyways for your help. <3
Is3dpic
Posts: 16
Joined: Mon Aug 25, 2008 6:12 pm

Post by Is3dpic »

It's not the end lol.
What does m_guienv->getRootGUIElement() really do ? Look my code :

Code: Select all

if (LogInButton->isPressed())
{
	IGUIElement* root = m_guienv->getRootGUIElement();
	IGUIElement* e= root->getElementFromId(loginPasswordBox->getID(), false);
	if (e)  e->remove();

}
It's delete the loginbutton and not the loginpasswordbox as expected and that I think because of getRootGUIElement() function...some lights plz thanks
Is3dpic
Posts: 16
Joined: Mon Aug 25, 2008 6:12 pm

Post by Is3dpic »

Ok :


Returns the root gui element.

This is the first gui element, parent of all other gui elements. You'll never need to use this method, unless you are creating your own gui elements, trying to add them to the gui elements without a parent.

and lol, LoginButton is first thing created so it's the parents, what Can I do now ? I want to delete the loginbutton and loginusernamebox, I think I'll have to mess with parents thingy, I'm digging api..
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Is3dpic wrote:

Code: Select all

IGUIElement* e= root->getElementFromId(loginPasswordBox->getID(), false); 
huu, why you're getting the element by it's id if you already have the element, where you get the id to search for from ?!?!? :shock:
if you already have the pointers stored why not simply use them ??? ;)

Code: Select all

loginPasswordBox->remove();
loginbutton->remove();
loginusernamebox->remove();
or you can create one parent that holds all controls as childs so you just need to remove this single parent... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

At least someone's awake, Acki!
Image Image Image
Is3dpic
Posts: 16
Joined: Mon Aug 25, 2008 6:12 pm

Post by Is3dpic »

Acki wrote:
Is3dpic wrote:

Code: Select all

IGUIElement* e= root->getElementFromId(loginPasswordBox->getID(), false); 
huu, why you're getting the element by it's id if you already have the element, where you get the id to search for from ?!?!? :shock:
if you already have the pointers stored why not simply use them ??? ;)

Code: Select all

loginPasswordBox->remove();
loginbutton->remove();
loginusernamebox->remove();
or you can create one parent that holds all controls as childs so you just need to remove this single parent... ;)
yes,

Code: Select all

loginPasswordBox->remove();
loginbutton->remove();
loginusernamebox->remove();
Yes, It's removes but It's make application crashing.

Also, I've tried :

Code: Select all

IGUIElement* parent;
and i've added all the buttons etc like that :
LogInButton = m_guienv->addButton( rect<s32>(330, 360, 430, 400), m_parent, -1, L"Log In" );
But I always end up with an error when I do m_parent->remove;
Last edited by Is3dpic on Wed Oct 29, 2008 2:14 pm, edited 1 time in total.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Is3dpic wrote:Yes, It's removes but It's make application crashing.
how does it crash, what error message do you get ???

maybe you try to access them after removing ???
try to set the pointers to 0 after removing and always check if it's =! 0 before accessing them...

Code: Select all

loginPasswordBox->remove();
loginPasswordBox = 0;
loginbutton->remove();
loginbutton = 0;
loginusernamebox->remove();
loginusernamebox = 0;
and later:

Code: Select all

if(loginusernamebox) theName = loginusernamebox->getText();
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Is3dpic
Posts: 16
Joined: Mon Aug 25, 2008 6:12 pm

Post by Is3dpic »

Yeap, thats it ! thanks you vey munch, It's now working . :P
Post Reply