# [Solved] I'm trying to make a Flashlight battery but don't know how to

I asked how to toggle a flashlight on and off yesterday and now I’m trying to make a flashlight battery for it. I have a variable set up for it but I can’t seem to get it to go down when the Flashlight is toggled. Can somebody help me?

At begin you hide the sprite torcg. Where do you show it?

Do you mean you want the battery to run down? If so, you’ll need to add an event that checks if the variable flashlightToggle is true, and reduce the value of flashlightBattery by an amount. Keep in mind this is done every frame, so I’d suggest you work out the rate you’d like to drain the battery per second, and subtract this value * TimeDelta().

So, for example, if you want to drain the battery by 2 every second, use the action flashlightBattery -= 2*TimeDelta().

This will reduce the flashlightBattery evenly.

I don’t understand what you mean

This works! But when it’s shown on text, it’s a whole string of numbers, and I don’t know how to round with TimeDelta. Is it possible to round the number with the TimeDelta expression?

Edit: I’ve tried and Round and Trunc expressions and it won’t go down.

Oh yeah, don’t worry about that, that was a old way I did the Flashlight toggle, but I redid it a easier way.

TimeDelta() will reduce flashlightBattery by a very small amount every frame (in your case probably something around 0.008), but when you add these values together, it’ll add up to 0.5 after a second has passed.

If you truncate or round TimeDelta(), you’ll get 0. So it’s best not to trunc or round TimeDelta(). It’d be better (and make more sense) to trunc or round flashlightBattery as you display it. so when setting the text object use `Set the text of FlashlightBattery = "Flashlight: " + ToString(round(Variable(flashlightBattery)))`.This will keep the decrease accurate, and only display the integer part of the battery value.

If you must trunc/round TimeDelta, then multiply it by 1000 (or more) first, then round/trun, and then divide by that same number. Something like `flashlightBattery -= round(TimeDelta()*1000/1000`. This will work, but be a little less accurate over time.

This works! Thanks a lot