À»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»""""""""""""""""""""""""""""""""33333333333333333333333333333333DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUffffffffffffffffffffffffffffffff > ÀÌÌÀ ÌÌÀ À ÌÀÌ ÌÀ À ÌÌÀ À ÌÀÌ Ì ÌÌÀ ÌÌÀÌ À ÀÌÌÌÌÌ ÀÌÌ ÀÌÀÌ À ÌÌÀÌ À ÀÌÌÌÌ Ì À À ÀÌÀ ÀÀ ÌÀ Ì ÌÌ Ì Ì ÌÀ À À ÀÌÀ ÀÀ ÌÀ Ì Ì Ì À À ÀÌÀ ÀÀ Ì ÌÀ Ì ÀÌÌ À À ÀÌÀ ÀÀ Ì ÌÀ ÀÌÌÌ À À ÌÌÀÌ Ì ÀÌÌÀÌÌ ÀÌ ÀÌÀÌ À ÌÌÀÌ Ì ÀÌÌÀÌÌÀÌÌÀÌ ÌÌÌÌÌÌ """ """ " " À Ì Ì ÌÀ Ì"" " "  À Ì Ì ÌÀÌ"" """"ÀÌ ÌÌÌÌÀÌÌ "" ""  "ÌÌ "ÌÀÌ ÌÌÌÌÌÌ """ """ " " À Ì Ì ÌÀ Ì"" " "  À Ì Ì ÌÀÌ"" """"ÀÌ ÌÌÌÌÀÌÌ "" ""  "ÌÌ "ù -- title: Table Demo -- author: Morokiane -- desc: A small demo on moving/removing objects in tables -- script: lua --[[This demo uses table.move. It doesn't really move objects but copies them to another table. To actually do a move the "moved" object needs to be removed from the table after being copied.]] w,h=240,136 hw,hh=w/2,h/2 t=0 win={} msgbox=true txt="Up/Down\nAdd objects to table\n\nLeft/Right\nMove objects between tables\n\nZ remove from top of Obj table\n\nX remove from bottom of Obj table\n\nA to close this window." --Easier controls to remember c={ up=0, down=1, left=2, right=3, z=4, x=5, a=6, s=7 } --Setup the two tables obj={} moved={} function OVR() if msgbox==true then AddWin(hw,hh,150,75,3,txt) end end function TIC() cls() if msgbox==false then print("Obj Table: "..#obj,0,0,12) print("Moved Table: "..#moved,110,0,12) --[[Print the objects that are in the tables down the screen]] for counter=1,#obj do print(obj[counter],0,(counter*8),12) end for counter=1,#moved do print(moved[counter],110,(counter*8),2) end if btnp(c.up) then table.insert(obj,"orange") end if btnp(c.down) then table.insert(obj,"apple") end if btnp(c.right) then --[[A local variable needs to be setup to add one to the index. LUA starts tables at 1 and not 0 so 1 needs to be added or the object will have nowhere to move since index 0 doesn't exist]] local i=#moved+1 --[[Move object 1 through 1 in obj to index 1 to moved. If more than one object needs to be moved at once, say 3 objects, change the second 1 in table.move to 3. table.remove will need to be updated to remove the 3 objects from the other table.]] table.move(obj,1,1,i,moved) table.remove(obj,1) end if btnp(c.left) then local i=#obj+1 table.move(moved,1,1,i,obj) table.remove(moved,1) end --Remove first object in table if btnp(c.z) then table.remove(obj,1) end --Remove last object in table if btnp(c.x) then table.remove(obj,#obj) end end if btnp(c.a) then msgbox=false end end function AddWin(x,y,w,h,col,txt) for i=1,#win do table.insert(win,i,#win) --[[.insert(table,position,value) win is the array/position is. i which iterates through the number of objects in the array / #win is where to put the values]] end rect(x-w/2,y-h/2,w,h,col) rectb(x-w/2+1,y-h/2+1,w-2,h-2,12) print(txt,x-w/2+3,y-h/2+3,12,0,1,true) end function DrawWin() for w in pairs(win) do rect(w.x,w.y,w.w,w.h,2) end end