Pulp tricks, maybe they help someone

I have to post this one fresh from the oven, as I struggled with it quite a bit today - mostly with trying to isolate the issue, create a scenario to reproduce it 100% of the time, then to find a workaround to how Pulp works.

I was implementing moving arrows, which use a wait between each movement step - simple stuff. BUT! When you change rooms or call fin, the wait calls for the tiles in the previous room do not get cancelled. So the code inside the wait can still execute in the new room. Or in the case of the fin call, it has a chance to execute on the same frame as the fin call, depending on the execution order (this one is a bit more complicated to get into). For this second case, which I use when restarting a room, I have this little bit of code:

restart = 1
store "restart"
wait 0 then
	fin "Restart message"
end

For exiting the room through a room connection, I use a collectible item placed on the exits, with the following code inside:

on pickup do
	nextRoom = currentRoom
	nextRoom++
	roomName = "room{nextRoom}"
end

This is vital! I also set the roomName inside the enter event of each room, but it's not enough, as between the player exiting the room and the enter event of the next room being called, depending on how those wait calls finish, you might have one exactly in between. The code above makes sure that roomName is already updated in case that happens.

Then, in my moving arrows script I have the following checks:

on move do
	wait arrowTime then
		if restart==1 then
			done
		elseif roomName!=event.room then
			done
		end
		// do move code here and call 'move' again
	end
end

Those checks make sure that we're not restarting the game and we're still in the same room as this tile. Why the second part? Well, I have to thank this nice thread where Scott is complaining that when calling a wait, the event.room variable remains set to what it was when calling that event, not to what it should be after the wait finishes. And one man's complaint is another man's solution! Since event.room after the wait will return the room name for my tile, I just compare it to the roomName as set by either the room enter event or the call from that collectible placed on the exit of the previous room.

I have no idea if all I've written above makes much sense, I'm way too tired, but if you need me to explain it better, please let me know. Alternatives solutions are also very welcome! Scott's approaches in the mentioned thread above are very useful and worth checking out too.

1 Like