Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(3 edits)

i is overwritten in this Java construct? Interesting. I'm only (a little) familiar with Lua and Python and both would treat the two i variables as distinct local variables.

Python:

text = ""
for i in range(3):
    text += "\n{}: ".format(i)
    for i in range(2):
        text += "{} ".format(i)
else:
    print(text)

outputs:

0: 0 1
1: 0 1
2: 0 1

Lua:

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

outputs:

0: 0 1
1: 0 1
2: 0 1

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