Variable that counts down on screen?

I'm trying to implement a system where the player only has limited moves on the board before they lose.
This is what I have so far:

on draw do
label "fuel:" at 2,1
label "{fuel}" at 5,1
end

on update do
if event.dx==-1 then

	fuel--
elseif event.dx==1 then
	
	fuel--
elseif event.dy==-1 then
  
	fuel--
elseif event.dy==1 then

	fuel--
else
end

if fuel==-10 then
	fin "You ran out of fuel and broke down!"
	
end

The problem is 'fuel' by default starts at 0 and counts down into negative numbers. I've tried using

on draw do
fuel = 10

But this stops it from counting down and just leaves a static number 10 on screen and never calls the 'fin' command. Is there a way to make the fuel counter start at a positive number and count down, ending the game at 0?

The draw event runs every frame, so if you set fuel to 10 there, it will always be reset to 10 every frame (20 times a second). You could try setting fuel to 10 in the load event in your game script, or the enter event on your player. Those only run once, the first when the game is loaded, and the second when a new room is displayed.

2 Likes

I've used the enter event and that's worked! Thanks very much