Madison Weaver / Guides

PICO-8 Basics

19, November 2022

While your program runs, PICO-8 will special functions. Each are prefixed with an underscore (_).

FUNCTION _UPDATE60()
  - YOUR UPDATE LOGIC HERE
END

_INIT()

The PICO-8 engine will call _INIT() when the program starts. While you don’t need to define this function for your program to run, using this method to define your initial values keeps your program organized.

-- RUNS ONCE WHEN THE PROGRAM STARTS
FUNCTION _INIT()
  -- INITIALIZE STATE
  GAMEOVER=FALSE
  RUNNING=TRUE
  PLAYER=1
END

_UPDATE()

The PICO-8 engine will call _UPDATE() 30 times per second. In most programs, you should use this function to capture user input and update your program state.

-- RUNS 30 TIMES PER SECOND
FUNCTION _UPDATE()
  -- CAPTURE INPUT
  IF BTN(➡️) THEN
    PLAYER_DIRECTION=➡️
  END

  -- UPDATE STATE
  IF (PLAYER_DIRECTION==➡️) THEN
    PLAYER_X+=1
  END
END

_UPDATE60()

Alternatively, you can define a function called _UPDATE60(). This function will be called 60 times per second instead of 30. This cause your _DRAW() function to be called 60 times per second as well.

-- RUNS 60 TIMES PER SECOND
FUNCTION _UPDATE60()
  -- CAPTURE INPUT
  IF BTN(➡️) THEN
    PLAYER_DIRECTION=➡️
  END

  -- UPDATE STATE
  IF (PLAYER_DIRECTION==➡️) THEN
    PLAYER_X+=1
  END
END

_DRAW()

PICO-8 will call _DRAW() after every _UPDATE() (or _UPDATE60()) call. You should use this function to draw elements onto the screen (e.g. shapes, sprites, pixels).

⚠️ PICO-8 will not automatically clear the screen before _DRAW() is called. In most cases, you should do this at the beginning of your function by calling CLS().

Typically, you should clear the screen before drawing elements.

-- RUNS AFTER EACH _UPDATE() CALL
FUNCTION _UPDATE60()
  -- CLEAR THE SCREEN
  CLS()

  -- DRAW ELEMENTS
  SPR(1,0,0)
END