Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Code Snippets

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]

Postby 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:
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
Fresh Boarder
 
Posts: 13

Re: New to LUA need help with code

Postby 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.
PureEnergie
Fresh Boarder
Fresh Boarder
 
Posts: 5
Location: Switzerland

Re: New to LUA need help with code [Solved]

Postby vshubh123 » 10 Oct 2011, 18:10

Thanks, it worked
vshubh123
Fresh Boarder
Fresh Boarder
 
Posts: 13

Re: New to LUA need help with code[solved]

Postby 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
Expert Boarder
 
Posts: 106

Re: New to LUA need help with code[solved]

Postby 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 ) )


:)
User avatar
soybean
Senior Boarder
Senior Boarder
 
Posts: 73


Return to Code Snippets