Hardware Crash calling 'fin' - but same code runs fine in Pulp simulator - any ideas?

So I'm completely new to game development (unless you count typing out games in basic for the ZX Spectrum back in the day). Thanks to excellent intro to pulp videos from SquidGodDev I got some linked levels running in Pulp but when run on actual hardware it was crashing when calling fin. I've found a workaround but just wondered if anyone had any ideas as to why?

Situation was that when the player position was the same as an enemy sprite, the sprite would tell event.game to call 'damagePlayer'. Then within damagePlayer I had sound "ouch" and health-=1 followed by a check for if health<=0 then fin
This ran fine in the simulator but crashed the playdate with an " attempt to index a nil value" . There were two sprite instances in separate rooms calling damagePlayer in this way and it was only the first one that caused the crash on the hardware. (I had the same issue when damagePlayer was called by event.player too)

My workaround is that damagePlayer now checks if health<=0 and then presents ' ask ' with options to continue or not. The 'continue' option under ask calls 'fin' and this works fine in all instances on simulator and hardware.

Just wondered if anyone had any idea why this was happening or what I had possibly done wrong in my first use case?

I'm not sure why, but there do seem to be some issues when it comes to fin on actual hardware. Someone else made a game which would end correctly using Pulp in a browser (fin being called from an item I think), but it would cause the Playdate hardware to crash. Not the same issue as you have, but there seem to be some bugs there.

1 Like

I'm going to test out your timing theory. There's another game I've found with the same issue, so hopefully I can compare and work out where/why its failing on the hardware. I think ultimately it comes down to the fact that the simulators are not emulators and so there will always be differences when run on real hardware. So glad my playdate finally arrived so I can test!

Hello!

I had exactly the same issue. I have a main menu with a "new game" option, that calls toss and then fin. In pulp it works perfectly, but in the actual Playdate appears exactly the same message as @twelfthman said.

You could try wrapping your fin call in a wait like this:

wait 0 then
  fin "Your ending text"
end

wait 0 is a neat way of delaying something until the next frame, which sometimes solves weird behaviour like this (or at least it has for me in the past!).

2 Likes

Yeah, I did try that. My intention was to create a 'new game' option without the need from the player to exit the game and open it again, but it was futile. Now I force them to do so, but as my game doesn't need to start all over again often, it's a necessary friction, I guess.

This resolved the issue in Pulp, playing on the web player. Thanks!

1 Like