I have seen this in other games so I know its possible but I have no idea on how to start.
Im scripting an energy meter which shows how much energy has been used.
My goal is to make it analog sytled. Not digital so it rounds the number away.
I have seen this in other games so I know its possible but I have no idea on how to start.
Im scripting an energy meter which shows how much energy has been used.
My goal is to make it analog sytled. Not digital so it rounds the number away.
You can use the string.format
function. The first argument for it is a string that contains the text in which the number should be and some format characters at the correct location in this text for telling how the number should be displayed. The second argument is the number. If you have multiple numbers or other things to format, include formatting characters for each one in the first argument and give the numbers as other arguments in the correct order.
local energyNumber = 2.3
local stringWithCorrectlyFormattedNumber = string.format("Energy: %.2f", energyNumber)
print(stringWithCorrectlyFormattedNumber) -- Energy: 2.30
Here are a couple of scripting support threads about formatting strings:
In one of them, this useful page about the string library (https://www.lua.org/pil/20.html) was linked.
Thank you very much. It helped me alot.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.