Posted 07 July 2013 - 01:44 PM
I am sure this is because of some small error I am doing / something I have misunderstood. I came across this when making a program that monitors my wireless turtles. I am sending out a message on the rednet and trying storing the status for each turtle that reports back in a table with their computer ID as the key. Looking at http://www.lua.org/pil/2.5.html I was assuming that I should be able to set numeric keys other then "the first one" / 1, but this doesnt seem to work as I expected.
I have been trying things out in a small test program I made to narrow down what I was struggling with:
This gives me the following output:
I was expecting this to set all three keys actually, based on the examples I have found etc. Could one of the pros (or maybe even noobs?) give me a hint as to what I have misinterpreted about hos Tables work in Lua ?
I have been trying things out in a small test program I made to narrow down what I was struggling with:
t = {}
function setit(cid)
t[cid] = "somevalue"..cid
end
print("13 Table size was "..table.getn(t))
setit(13)
print("13 Table size is now "..table.getn(t))
textutils.tabulate(t)
print("1 Table size was "..table.getn(t))
setit(1)
print("1 Table size is now "..table.getn(t))
print("15 Table size was "..table.getn(t))
setit(15)
print("15 Table size is now "..table.getn(t))
textutils.tabulate(t)
This gives me the following output:
13 Table size was 0
13 Table size is now 0
1 Table size was 0
1 Table size is now 1
15 Table size was 1
15 Table size is now 1
somevalue1
I was expecting this to set all three keys actually, based on the examples I have found etc. Could one of the pros (or maybe even noobs?) give me a hint as to what I have misinterpreted about hos Tables work in Lua ?