How do I print the first position value of a table in table

SheetInfo = {}
SheetInfo.frameIndex =
{
[“capguy/walk/0001”] = 1,
[“capguy/walk/0002”] = 2,
[“capguy/walk/0003”] = 3,
[“capguy/walk/0004”] = 4,
[“capguy/walk/0005”] = 5,
[“capguy/walk/0006”] = 6,
[“capguy/walk/0007”] = 7,
[“capguy/walk/0008”] = 8,
[“city_background”] = 9,
[“capguy/walk/0010”] = 10,
}

How do I access the table above and print out “capguy/walk/0001” ?
I’ve tried
print(SheetInfo.frameIndex[1])
but not working.

*I know about key,value pairs and the code below prints all the keys but I just want to print out the first position. How do I?

for k,v in pairs(SheetInfo.frameIndex) do
print(k)
end

for k,v in pairs(SheetInfo.frameIndex) do
   if v == 1 then
     print(k)
   end
end

Your index is the value, rather than the key. To print 1 instead, do print(SheetInfo.frameIndex[“capguy/walk/0001”])

1 Like

@StarCrunch Thank you!

If you need a way to make quick experiments and test with Lua language I can suggest you this:

https://www.tutorialspoint.com/execute_lua_online.php

is an online Lua interpreter
Renato

I have LUA installed on my computer and can access it in Visual Studio Code as well as Codea, thanks though.

For small Lua or Solar2D projects, you could also always use https://www.solar2dplayground.com/.

2 Likes