Log In  


Here's a small code snippet that allows you to enter "debug mode" and then go frame by frame through your game.

The idea is, that _update() wraps the actual update() function, and _draw() wraps the actual draw() function.
So you can have extra output only drawn in debug mode, and go frame by frame through the game to do some bug hunting.
It would also allow to append to a debug file only if debug mode is enabled.

It's pretty simple code, but quite helpful.
To switch to release mode, all you need to do is to swap the names of _draw() and draw() and _update() and update().

function _init()
 poke(0x5f2d, 0x01)
 debug=false
 waitframe=false
 t=0
end

function _update()
 if stat(30) then
  local ch=stat(31)
  if ch == "d" then
   if debug then
    waitframe = false
    debug = false
   else
    debug=true
   end     
  end
  if debug and ch==" " then
   waitframe = false
  end
 end

 if not waitframe then
  update()
  if debug then
   waitframe = true
  end
 end
end

function update()
 t+=1
end

function _draw()
 draw()
 -- debug information here
 if debug then
  print(debug,0,123,7)
 end
end

function draw()
 cls()
 print(t,2,2,7) 
end
5


Hi @spellcaster:

Pico-8 actually does come with some powerful debugging tools. They are explored those in this cart I wrote HERE:

https://www.lexaloffle.com/bbs/?tid=35702


can you explain the difference with the built-in step-by-step mode? https://www.lexaloffle.com/dl/docs/pico-8_manual.html#RESUME


Sure. One allows you to stop the game ad then type commands and step forward.
The other allows you to do this while inside the game.
And, with slight modifaction allows you also to slow/down speedup the game. it also allows you to display certain information only when needed w/o having to exit the game, etc.

It's a different use case.


ok, that sounds great! thanks for replying!



[Please log in to post a comment]