How can I get a text from textinput only knowing the 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.
sanctus2099
Posts: 18
Joined: Sat Nov 17, 2007 11:34 am

How can I get a text from textinput only knowing the id?

Post by sanctus2099 »

Okay... so I have the id of a gadget in a int
Is there a way to get a pointer to a gadget by the id or anyother way to find out what is in the textinput just by knowing the id?
shogun
Posts: 162
Joined: Wed Sep 05, 2007 11:02 am
Location: inside

Re: How can I get a text from textinput only knowing the id?

Post by shogun »

sanctus2099 wrote:Okay... so I have the id of a gadget in a int
Is there a way to get a pointer to a gadget by the id or anyother way to find out what is in the textinput just by knowing the id?
((gui::IGUIEditBox*)getElementFromId(YOUR_ID, true))->getText();

getRootGUIElement() also may be of interest for you, if you don't have a IGUIWindow where your Editbox is placed. Just search the docs.
sanctus2099
Posts: 18
Joined: Sat Nov 17, 2007 11:34 am

Post by sanctus2099 »

Thx dude... ;)
sanctus2099
Posts: 18
Joined: Sat Nov 17, 2007 11:34 am

Post by sanctus2099 »

Okay... I didn't test it back then but I tought it would work(had some other problems).
THe things is that it doesn work... somehow there is no function like getelementfromid. I'd love if the docs would have a search
shogun
Posts: 162
Joined: Wed Sep 05, 2007 11:02 am
Location: inside

Post by shogun »

Yes, there is such a function.

You can use Google, can't you?

http://irrlicht.sourceforge.net/docu/cl ... nt.html#a6
sanctus2099
Posts: 18
Joined: Sat Nov 17, 2007 11:34 am

Post by sanctus2099 »

Thx... It works now.
Any ideea how to transform a whcar_t array to a string? I need to send it trough network.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

search the forum as this has be answered lots, or look at core::stringw
Image Image Image
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

right, always search the forum first !!! :roll:

well, just in case you're to dump to do a search :twisted:
try this thread: http://irrlicht.sourceforge.net/phpBB2/ ... rt+convert

but seriously, please search the forums before asking, it usualy will save a lot of time for all of us !!! :lol:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
sanctus2099
Posts: 18
Joined: Sat Nov 17, 2007 11:34 am

Post by sanctus2099 »

Okay... my bad... I did look a litle into the search but didn't find exactly what I wanted... its ok now... next problem...

Code: Select all

IGUIElement* elem;
		char temp[255];
		wcstombs(temp, elem->getElementFromId(nameid)->getText(), 255);
It does compile... but when it passes those lines it breaks and says something about it not beeing defined... could someone please recode that small thing? pls
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

sanctus2099 wrote: ... but when it passes those lines it breaks and says something about it not beeing defined...
Always funny when people try to summarize error messages instead of just pasting them :-) That exact (and complete!) error message is the thing we need to help you ...
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

my guess is getElementFromId is returning NULL..

Does getElementFromId only search the children of that element and seeing as elem has just been declared as a solitary element it won't find anything...
Image Image Image
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

right, because IGUIElement* elem; is undefined garbage and you try to get an element from it... ;)
so change

Code: Select all

elem->getElementFromId(nameid)->getText()
to

Code: Select all

guienv->getElementFromId(nameid)->getText()
or whatever your gui environment is defined in... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
sanctus2099
Posts: 18
Joined: Sat Nov 17, 2007 11:34 am

Post by sanctus2099 »

Code: Select all

c:\SanctusOnline\IntfFunctions.cpp(21): error C2039: 'getElementFromId' : is not a member of 'irr::gui::IGUIEnvironment'
        c:\SanctusOnline\Irrlicht\IGUIEnvironment.h(55) : see declaration of 'irr::gui::IGUIEnvironment'
I allready tryed that. Is there a way to get the masterparent of all gui elements?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

sanctus2099 wrote:I allready tryed that. Is there a way to get the masterparent of all gui elements?
ohh, my fault, I just looked at your code and made a quick post... ;)
but why you didn't simply look at the api, it's a realy magical file that tells you all about Irrlicht's elements and their functions !!! :roll:

so the code must (of course) be:

Code: Select all

guienv->getRootGUIElement()->getElementFromId(nameid)->getText()
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You're forgetting that you need to tell the call to recursively traverse the element graph...

Code: Select all

gui::IGUIElement* found = gui->getRootElement()->getElementFromId(id, true);
if (found)
{
    const wchar_t* wstr = found->getText();
}
Travis
Post Reply