Displaying a dynamic variable on screen

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
Viking86
Posts: 24
Joined: Tue Apr 20, 2010 2:29 pm

Displaying a dynamic variable on screen

Post by Viking86 »

Greetings , whats the easiest way to show a changing variable on screen ?, I have a global variable which is changable during the program run time.
I simply want to have a display of the variables current value in the window.

I looked at the tutorial 9 which had something similar

Code: Select all

 gui->addEditBox(L"1.0", core::rect<s32>(100,46,130,66), true, 0, GUI_ID_X_SCALE);
	 IGUIElement* toolboxWnd = device->getGUIEnvironment()->getRootGUIElement()->getElementFromId(GUI_ID_DIALOG_ROOT_WINDOW, true);
	 toolboxWnd->getElementFromId(GUI_ID_X_SCALE, false)->setText(setText( [b]core::stringw(scale.Z).c_str() [/b]);
how do I pass a float variable to the setText function?
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: Displaying a dynamic variable on screen

Post by randomMesh »

Viking86 wrote:how do I pass a float variable to the setText function?

Code: Select all

irr::gui::IGUIStaticText* myText = guienv->addStaticText(L"", ...);
//....
myText->setText(irr::core::stringw(myFloatVariable).c_str());
Last edited by randomMesh on Fri May 14, 2010 1:59 pm, edited 1 time in total.
"Whoops..."
Viking86
Posts: 24
Joined: Tue Apr 20, 2010 2:29 pm

Re: Displaying a dynamic variable on screen

Post by Viking86 »

randomMesh wrote:
Viking86 wrote:how do I pass a float variable to the setText function?

Code: Select all

irr::gui::IGUIStaticText myText = guienv->addStaticText(L"", ...);
//....
myText->setText(irr::core::stringw(myFloatVariable).c_str());
Thank you very much

Code: Select all

irr::gui::[b]IGUIStaticText*[/b] myText = gui->addStaticText(L"",core::rect<s32>(0,200,100,220), false, false, 0, -1, true);
had to add the "*" and it works like a charm :)
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: Displaying a dynamic variable on screen

Post by randomMesh »

Viking86 wrote:had to add the "*" and it works like a charm
Sorry, of course addStaticText returns a pointer. Such things happen fast when typing code out of your head. :)
"Whoops..."
Brainsaw
Posts: 1243
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Post by Brainsaw »

I prefer using swprintf because of the format possibility:

Code: Select all

  wchar_t s[0xFF];
  swprintf(s,0xFF,L"aValue: %.2f fps",aValue);
  aStaticText->setText(s);
Image
Dustbin::Games on the web: https://www.dustbin-online.de/
Post Reply