Hi! I've been playing pico-8 games for a few years, but I just recently started playing around with coding it, so I'm a newb to pico-8 and lua programming.
I don't get it why this wouldn't work, it just prints out 1 2 3, could someone please point me in the right direction?
I first tried to put the random function straight into the add function, but that didn't work, so that's why i here try to put it into the 'randy2' variable first.
add(rndorder,flr(rnd(3))+1) |
I also tried to add the random value manually (row by row) into the table, but that didn't work either :(
rndorder[1]=flr(rnd(3))+1 rndorder[2]=flr(rnd(3))+1 Etc. |
Why wouldn't this add 7 random numbers into the 'rndorder' table and print them out?
rndorder={} palt(0, false) --transparency palt(2, true) function _init() function populate_rndorder() x=1 while(x<=7) do randy2=flr(rnd(3))+1 --int random add(rndorder, randy2) x=x+1 end end populate_rndorder() end function _update() -- end function _draw() cls() map() for v in all(rndorder) do print(v,v*8,v*8,10) end end |
I saw this other random thread
https://www.lexaloffle.com/bbs/?tid=3959
where someone gives the example:
function _init() balls={} for i=1,500 do add(balls,rnd()) end end |
I don't see the difference.
Any help appreciated!



It does - you are using the value as coordinates.
Given that values are only 1,2 or 3 - you are simply printing multiple times at the same location.
"Fixed" version:
local rndorder={} palt(0, false) --transparency palt(2, true) function _init() for x=1,7 do add(rndorder,flr(rnd(3))+1) end end function _update() -- end function _draw() cls() local y=2 for v in all(rndorder) do print(v,2,y,10) y+=6 end end |



Thanks man! Very nice of you! What a silly mistake, I apparently didn't read i.e. understand the print function properly, I missed that it printed the values.
[Please log in to post a comment]