About Text.

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
fon3m
Posts: 32
Joined: Thu Sep 28, 2006 9:34 pm

About Text.

Post by fon3m »

I want to show text when open the door(with out key), get a key, etc.
I use addStaticText() to draw. but when i want to change text , i can't change it because i don't know function for change text. i would like to know that addStaticText() have function to change text? and have function to move this text? if addStaticText() can't do that, what function can do it?

Thank you
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Always check the API for these kind of questions as the answers are there!

When you add the static text with addStaticText it returns a pointer to an IGUIStaticText, keep that pointer and then when you want to change it you can use the setText() function.
Image Image Image
fon3m
Posts: 32
Joined: Thu Sep 28, 2006 9:34 pm

Post by fon3m »

I do this code

Code: Select all

IGUIElement* text3;
text3->setText(L"555...");
text3->setRelativePosition (core::rect<s32>(100,10,184,99));
text3->draw();
but it's error and close windows. What's wrong? :(
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

text3 is an invalid pointer, you never assign anything to it. And as far as i know you don't have to call draw().
Image Image Image
fon3m
Posts: 32
Joined: Thu Sep 28, 2006 9:34 pm

Post by fon3m »

I think setText() is an assign. I don't understand.
Um........... Did you have sample for me?

Thank you
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

setText would assign if you had a valid IGUIStaticText pointer, but you don't because you havn't got "text3 = gui->addStaticText(..)"
Image Image Image
zeno60
Posts: 342
Joined: Sun May 21, 2006 2:48 am
Location: NC, USA
Contact:

Post by zeno60 »

I don't belive the setText method will do what you are asking because you have defined text as type IGUIElement. Which has a setText() method to set the caption of the element. I think you would have to define it as type IGUIStaticText which overrides the setText() method to set the text of the string. Am I right?

IGUIStaticText* text;
text = env->addStaticText(L"Text",rect<s32>(10,10,500,28), false,true);
// text will be shown as "Text"

text->setText(L"blah");
// text will now be "blah"

EDIT: Just tried it and i'm wrong, you can have it as IGUIElement and still change the text with setText, but you lose the color override function. Commence playing Price is Right loser theme here.
fon3m
Posts: 32
Joined: Thu Sep 28, 2006 9:34 pm

Post by fon3m »

I saw in doc of engine that
"text is the text to be displayed. Can be altered after creation with SetText(). "

and I do this

Code: Select all

text1 = irrDevice->getGUIEn();
text1->addStaticText(L"You must find a key to open this door. ",core::rect<s32>(110,10,300,20), true, true, 0, -1, true);	
if(...)
{
    text1->setText(L"555");
}

error C2039: 'setText' : is not a member of 'IGUIEnvironment'
and I know that setText is member of IGUIElement but i don't know how to use this code.
zeno60
Posts: 342
Joined: Sun May 21, 2006 2:48 am
Location: NC, USA
Contact:

Post by zeno60 »

addStaticText() returns a pointer to the IGUIStaticText object within your GUIEnvironment, so assign a IGUIStaticText object to that returned pointer and use the object's setText method to change the text:

Code: Select all

text1 = irrDevice->getGUIEn();
IGUIStaticText* text = text1->addStaticText(L"You must find a key to open this door. ",core::rect<s32>(110,10,300,20), true, true, 0, -1, true);   
if(...)
{
    text->setText(L"555");
}
For readability and less confusion:

Code: Select all

IGUIEnvironment* env = irrDevice->getGUIEnvironment();
IGUIStaticText* text = env->addStaticText(L"You must find a key to open this door.", core::rect<s32>(110,10,300,20),true,true,0,-1,true);

if(...)
{
     text->setText(L"555");
}
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

fon3m wrote:I saw in doc of engine that
"text is the text to be displayed. Can be altered after creation with SetText(). "

and I do this

Code: Select all

text1 = irrDevice->getGUIEn();
text1->addStaticText(L"You must find a key to open this door. ",core::rect<s32>(110,10,300,20), true, true, 0, -1, true);	
if(...)
{
    text1->setText(L"555");
}

error C2039: 'setText' : is not a member of 'IGUIEnvironment'
and I know that setText is member of IGUIElement but i don't know how to use this code.
*bands head on table*

Do yourself a favour and learn C++ before starting on stuff that's too complicated for you!
Image Image Image
zeno60
Posts: 342
Joined: Sun May 21, 2006 2:48 am
Location: NC, USA
Contact:

Post by zeno60 »

JP wrote:Do yourself a favour and learn C++ before starting on stuff that's too complicated for you!
I get lectured at when I tell people this. Apparently I am critisizing peoples learning methods when I try to let people understand that Irrlicht is a rendering engine that uses C++, not that Irrlicht is a rendering engine that teaches C++.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I know, i'm turning into a bad man and hating n00bs which is wrong because we were all there once. But i just really think that a lot of these errors are simply from a lack of understanding of the language so basically just going to a website with some explanations and tutorials would do a world of good! Here's some that i used when i started changing over from Java to C++ earlier this year:

http://www.cplusplus.com/doc/tutorial/
http://www.cprogramming.com/tutorial.html
Image Image Image
fon3m
Posts: 32
Joined: Thu Sep 28, 2006 9:34 pm

Post by fon3m »

OH! Thank you very much. and sorry about my stupid.
Post Reply