Log In  



I have an array called mem (memory), and I store x and y values in it. It counts how many of a coordinate pair is in the list, and if there's none it does something and then adds it to the list, so that it can't do something to that coordinate again. But for some reason, even when it's in the list, it counts none.

The first value stored in it is {2,2}
The top three commands show that mem[1][1] is 2, mem[1][2] is 2, and that there's nothing after those two, so the first element in mem is definitely {2,2}, but when I try to count how many {2,2}'s are in mem, it returns 0. What's going on?



2

the issue boils down to this (try it in the pico8 terminal)

?{2,2}=={2,2}

(it's false !?)

It's false, because the tables are two different pieces of memory, and == on tables is defined to check if they're the same table object or not (it does not compare the tables' contents)


1

Okay, I did this, and it does exactly what I wanted count to do, so that's great

n=0
for i=1,#mem do
 if (mem[i][1]==gx and mem[i][2]==gy) n+=1 break
end
if n==0 then

Thanks for letting me know, I'll definitely make sure to keep that in mind from now on



[Please log in to post a comment]