So I recently was trying out PICO, messing to see what was possible, and was attempting to make a metal gear-styled game.
I wanted to try and limit how often PICO would read a button press. To do this I used the following code:
function framecount() frame = 0 frame += 1 if frame > 30 then frame = 0 end end function controls() if btn(0) then player.x-=1 end if btn(1) then player.x+=1 end if btn(2) then player.y-=1 end if btn(3) then player.y+=1 end end function _update() framecount() if frame = 30 then controls() end end |
The result ends with the Lua parser not seeing the
then |
placed after
if frame = 30 |
I know btnp can be used for this (though it would detect press every 4 frames, not every 30), but there are other things I want to tie into a frame delay and this was a way to test if the hack worked.
Also worth pointing out (maybe) that you're resetting frame to 0 every time you call framecount(), you should put that "frame=0" line outside of the function so it only gets run once. eg:
frame=0 function framecount() frame += 1 if frame > 30 then frame = 0 end end |
Or if you feel like being fancy you can put it in the _init() function, which is nearly the same, behaviorally:
function _init() frame=0 end |
[Please log in to post a comment]