I'm having trouble with a for loop. The code runs but it doesn't work as desired. Here's the code:
function pikmin_create(n) g = 1 for group in all(pikmin.sprite) do for i = 1,n do if g == 1 then add(pikmin.sprite[group],6) elseif g == 2 then add(pikmin.sprite[group],8) elseif g == 3 then add(pikmin.sprite[group],10) end end g+=1 end end |
pikmin.sprite is initalized in function _init() as follows:
pikmin = { sprite = {{},{},{}} } |
This should assign every group/subtable in pikmin.sprite a different sprite. However the assignment doesn't work (as the default 0 sprite gets printed).
What am I doing wrong?
P#127655 2023-03-27 12:42