Log In  
Follow
Necco
[ :: Read More :: ]

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:

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

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#36975 2017-01-31 16:39 ( Edited 2017-02-01 02:27)

Follow Lexaloffle:          
Generated 2024-04-19 01:25:28 | 0.063s | Q:5