Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you output a variable's value into a string?

Asked by 8 years ago

New to lua, mainly use ruby. In ruby, if i wanted to print a value, say, health, I could do

hp = 100
print "HP: #{hp} /100

and it would output "HP: 100/100"

How does this translate into lua? None of the results I found on google worked in studio.

1
print(hp .. "/100") GoldenPhysics 474 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

Hey, as far as I know numbers get automatically turned into strings when printed, I am not a 100% sure it is this way (let me know if it works) but I am pretty confident this is how you do it. Let's say you wanted to print the health of a humanoid.

Health = Humanoid.Health
print(Health)

now, if that doesn't work (it should), then you must explicitely tell the script to turn the numbers into a string, and you do that with the tostring function.

Health = Humanoid.Health
print(tostring(Health))

If it works please remember to accept the answer and upvote, thanks you and good luck :)

0
You can print numbers. You can print pretty much any value. User#11440 120 — 8y
0
You can convert anything to a string using 'tostring(value)'. If it does not work, it should return 'nil'. TheDeadlyPanther 2460 — 8y
Ad
Log in to vote
-1
Answered by
cc567 50
8 years ago

try

print(hp/100)

Answer this question