ShiVa3D
New to LUA need help with code[solved]
Paste down any little snippets or request a new one.New to LUA need help with code[solved]
by vshubh123 » 10 Oct 2011, 17:10
Hey guys
I was just wondering if someone could provide me a codesnippet to display the values of variables in a Hud label, i.e FPS or mouse location
I have the following code below that does not work:
If I change the replace the variable and give it a static value of something like : "12" It works. Code below:
I was just wondering if someone could provide me a codesnippet to display the values of variables in a Hud label, i.e FPS or mouse location
I have the following code below that does not work:
- Code: Select all
local variable = 12;
hud.setLabelText( hud.getComponent ( application.getCurrentUser ( ), "Hud.display" ) , variable )
If I change the replace the variable and give it a static value of something like : "12" It works. Code below:
- Code: Select all
hud.setLabelText( hud.getComponent ( application.getCurrentUser ( ), "Hud.display" ) , "12" )
Last edited by vshubh123 on 10 Oct 2011, 18:10, edited 1 time in total.
- vshubh123
- Fresh Boarder

- Posts: 10
Re: New to LUA need help with code
by PureEnergie » 10 Oct 2011, 17:38
I got the same Problem. Lua set your variable as an number. But you just can dislpay an String into the label. I was looking for an function to convert number to string and i didn't found one. Because i just need it for some tests into my game i sove this with an inelegantly solution. 
local nVariable = 12;
local sString = " " .. nVariable;
hud.setLabelText( hud.getComponent ( application.getCurrentUser ( ), "Hud.display" ,sString);
I hope it helps.
local nVariable = 12;
local sString = " " .. nVariable;
hud.setLabelText( hud.getComponent ( application.getCurrentUser ( ), "Hud.display" ,sString);
I hope it helps.
- PureEnergie
- Fresh Boarder

- Posts: 2
- Location: Switzerland
Re: New to LUA need help with code[solved]
by rusty » 21 Oct 2011, 22:41
Are you after the double dot string concatenation method?
- Code: Select all
hud.setLabelText(hud.getComponent(application.getCurrentUser(), "Hud.display"), "Speed: "..nVar)
- rusty
- Expert Boarder

- Posts: 95
Re: New to LUA need help with code[solved]
by soybean » 22 Oct 2011, 15:48
much cleaner with string.format:

- Code: Select all
hud.setLabelText( hud.getComponent ( application.getCurrentUser ( ), "Hud.display" ), string.format("%s", nVariable ) )
-

soybean - Senior Boarder

- Posts: 71
5 posts
• Page 1 of 1