Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Cool a fellow Lua coder!

But you don't necessarily have to use tostring() here, the following should work as well.

text = ""
for i = 0,2 do
    text = text.."\n"..i..": "
    for i = 0,1 do
        text = text..i.." "
    end
end
print(text)

Lua always tries to convert the i here into a string when possible. I think nil wouldn't get converted, and obviously lists can't get converted.

The same should be possible when adding a string that only contains numbers to an integer, the string gets converted to a number automatically.

local ans = 12+"012"
print(ans)

The 12+"012" returns 24 as a result, and so this prints in the next line.
The "012" get's converted to 12 as if you would do tonumber("012").
This usually saves some time when coding for me, so just a tip (I'm way to happy to see other people using lua XD)

(+1)

true - conversion works without "tostring()"

Nevertheless, the Lua guys recommend using it. That way, the interpreter doesn't have the extra task of finding out if a conversion is required or not. You state that it is.

The string.format() command would have been another option. Actually the nicest way to combine text and data into one string.


to Denki:
My apologies for abusing you forum for this off-topic talk :-)