r/pico8 • u/Few_Letter_9286 • May 15 '26
Game Help pls with code
if btn(⬆️) thengrav=grav-1if timer=0 thengrav=grav+1timer=timer+4elsetimer=timer-1end
0
Upvotes
r/pico8 • u/Few_Letter_9286 • May 15 '26
if btn(⬆️) thengrav=grav-1if timer=0 thengrav=grav+1timer=timer+4elsetimer=timer-1end
8
u/RotundBun May 15 '26 edited May 15 '26
Firstly...
The flair you want is the [I Need Help] flair.
Secondly...
For future reference, providing some context and formatting your code as a code block will help others help you.
--
With limited context, the 2 errors/bugs are:
(Also, rather than
timer=timer+4, it may be better to just set it directly astimer=4.)--
You can copy-paste your code here with formatting preserved by putting them between 2 lines of triple backticks (```).
```
```
The backtick (`) is on the tilde (~) key below [Esc] on a keyboard and behind the apostrophe (') on iOS (press & hold, leftmost option).
This will make it easier for others to help you.
Hope that helps. 🍀
4
u/Justin-Hufford May 15 '26
It does look like you’re missing an ‘end’ though. You have two if statements and only one end.
3
u/Synthetic5ou1 May 16 '26
On an unrelated note, you could write this like so:
Note that
+=and-=are not core LUA operators, but you can use them in PICO-8.Also, I assume that you are using
timerto delay the increase in gravity to once every 5 frames.Another way to do this is to just start
timerat 0, increase it every frame, and then use:The benefit of this is that you can trigger other actions at different intervals, all using the same
timervariable.1
u/Justin-Hufford May 15 '26
Could you give some more context? What are you trying to achieve? Are you getting an error message?
1
u/Gexgekko May 15 '26
You are missing an "end", and timer should be running constantly so either you have this on the main loop or you add a loop to the timer