So I started working with the PICO-8 web version this week, and I wanted to make a simple dungeon crawling game. I started working on the code and got the player sprite moving left and right. The next step was to keep the player on the screen.
So I began by using a boolean variable to keep track of whether the player was touching the edge of the screen: INBOUNDS
. Then I tried using an if statement to determine whether the x
coordinate was in the limits:
-- CHECK IF PLAYER IS IN THE SCREEN
IF (X = 0 OR X = 128)
INBOUNDS = FALSE
END
When the program ran, however, I got an error in the console that read:
SYNTAX ERROR LINE 22 (TAB 0)
IF (X = 0 OR X = 128)
')' EXPECTED NEAR '='
Here is the link to the cartridge file: https://drive.google.com/file/d/1H0snkt8oza1tXiy0__kTVUX7DMYvdJSr/view?usp=sharing
If you need any more info, please ask.
Thanks!
In this line, you are using the assignment operator
=
instead of equality operator==
:And in these lines, you are using bit-wise
&
operator instead of logicaland
:Here is a version close to yours that runs correctly:
You are clearing the screen and rendering the sprite in the
_update
function which is (I think) not correct.You should only change state in the
_update
function, and all graphics code (includingcls
andspr
) should be called in the_draw
function.Here is a slight rewrite which has the correct structure, clamping the player's dimensions to a fixed range using the
mid
function:Here's some more info on the
mid
function: https://pico-8.fandom.com/wiki/Mid