Hi AVARSStudios,
This can be done fairly quickly with booleans and a timer. I’ll include screenshots of how I did it.
Note: I didn’t actually do anything with a light here, I just put print strings in to make sure everything worked correctly.
To start off with, I made 3 variables. A boolean named bIsLightOn, another boolean bIsBatteryAlive, and an integer Battery. Be sure to set all of these to public to avoid issues.
The first part is the timer. I set it to 1.0 for the time, so every second, and put the Light function into it. We’ll see the function later. I then put a check in on Event Tick to check for when Battery runs out of juice. I then set up the toggling of the flashlight.
I then made a new function called Light and placed these nodes into it. The first branch checks to see if the light is on, if that’s true, it goes onto the next to check if the battery is alive. If it passes that, it’ll start subtracting 1 from battery. Seeing as the timer is set to loop, it’ll loop this every second and only subtract if the light is on. You can ignore the print strings, those were there for me to test if the function was doing what it was suppose to.
Hope this helps!