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
P#113573 2022-06-24 10:34

:: dw817

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

P#113591 2022-06-24 18:14 ( Edited 2022-06-24 18:14)
:: merwok

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

P#113618 2022-06-25 13:12

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.

P#113634 2022-06-25 16:41
:: merwok

ok, that sounds great! thanks for replying!

P#113637 2022-06-25 17:01

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2022-08-17 15:53:09 | 0.024s | Q:12