• Trouble with table
    4 replies, posted
Hello, im troubled with table. [LUA] local _table = { "10", "20" } for k, v pairs(_table) do --Here! How to plus 10 to every value? --v = v[i] + 15 end [/LUA] Please any suggestion, i can't solve this, maybe table.insert or what?
[code] local _table = { "10", "20" } local ret = 0 for k, v pairs(_table) do ret = ret + v end print(ret) [/code] Untested but should work.
You can't add a number to a string. You have to change "10","20" to 10,20. And then: [lua] for k, v in pairs(_table) do _table[k] = v + 10 end [/lua]
nvm, didnt read well, it should be [code] local _table = { "10", "20" } for k, v pairs(_table) do table.insert(_table, k, v+10) end [/code] [editline]17th August 2015[/editline] Ninja'd :v:
Thanks all!!
Sorry, you need to Log In to post a reply to this thread.