You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Need help with tables, I have a table with sprite numbers and want to create 2 copies in a new table with different positions if I trace the table after the table.insert command it looks OK but when I read them back out of the table its different.
Not sure where I am going wrong any help apricated.
init 256 - 14
init 256 - 2
init 257 - 13
init 257 - 11
list ip 256 - 2
list ip 256 - 2
list ip 257 - 11
list ip 257 - 11
list 256 - 2
list 256 - 2
list 257 - 11
list 257 - 11
Code>>>>
-- title: test add to table
-- author: Brian D Simonds [email protected]
-- desc: short description
-- site: website link
-- license: MIT License (change this to your license of choice)
-- version: 0.1
-- script: lua
rnd = math.random
tbl = {}
sprites = { { sprno = 256}, {sprno = 257 }}
function TIC()
init()
listIpairs()
list()
exit()
end
function init()
local obj = {}
local objnew = {}
for i, obj in ipairs(sprites) do
objnew = obj
for ii = 1, 2 do
objnew.x = rnd(1,17)
table.insert(tbl,objnew)
trace("init "..tbl[#tbl].sprno.." - "..tbl[#tbl].x)
end
end
end
function listIpairs()
local obj = {}
for i, obj in ipairs(tbl) do
trace("list ip "..obj.sprno.." - "..obj.x)
end
end
function list()
for i = 1, #tbl do
trace("list "..tbl[i].sprno.." - "..tbl[i].x)
end
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi
Need help with tables, I have a table with sprite numbers and want to create 2 copies in a new table with different positions if I trace the table after the table.insert command it looks OK but when I read them back out of the table its different.
Not sure where I am going wrong any help apricated.
init 256 - 14
init 256 - 2
init 257 - 13
init 257 - 11
list ip 256 - 2
list ip 256 - 2
list ip 257 - 11
list ip 257 - 11
list 256 - 2
list 256 - 2
list 257 - 11
list 257 - 11
Code>>>>
-- title: test add to table
-- author: Brian D Simonds [email protected]
-- desc: short description
-- site: website link
-- license: MIT License (change this to your license of choice)
-- version: 0.1
-- script: lua
rnd = math.random
tbl = {}
sprites = { { sprno = 256}, {sprno = 257 }}
function TIC()
end
function init()
end
function listIpairs()
local obj = {}
for i, obj in ipairs(tbl) do
trace("list ip "..obj.sprno.." - "..obj.x)
end
end
function list()
end
Beta Was this translation helpful? Give feedback.
All reactions