Necco [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=21204 How to clone tables? <p>Hello, I'm kinda new to Pico-8 and programming in general, and I'm trying to make a tetris game from scratch. Everything was going ok, but there's one thing that's bugging me: if I try to change a table that's a copy of another one, the original table also gets changed. I've made a simpler code to test if the problem was with some other function I wrote, but the problem persists. Here's the code:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> function _init() test={1,2,3} end function _update() if btnp(4) then local t=test t[1]=0 end end function _draw() cls() for i=1,count(test) do print(test[i],40+i*8,60,7) end end </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>If I execute this code and press Z, the first element of test changes, even though I only changed the local table t. What am I missing here?</p> https://www.lexaloffle.com/bbs/?tid=28765 https://www.lexaloffle.com/bbs/?tid=28765 Tue, 31 Jan 2017 16:39:54 UTC