Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

How can I change my flashlight / battery setup to be step-based instead of frame based?

ddblue0

Villager
Xy$
0.20
Hi everyone.
I've been struggling with this and asking around elsewhere, but I figured I'd ask here because I've seen you all answer some pretty complicated questions over the years.

I'm trying to create a flashlight / battery system.
I will decide the final values later, but for now I'd like a battery to go dead after 50 steps.
I've found several flashlight tutorials, but they're all frame based - I really want a step based system.

If you know of a way I can change my scripts to make a step-based system work, I'd really appreciate it.
Or better yet if you have an easier way of accomplishing this that's totally different than what I've written here, please let me know.


Here's what I tried:
1. Create 2 flashlight items. Flashlight ON and Flashlight OFF.
2. Created 3 common events: Flashlight ON, Flashlight OFF, and Flashlight ON FORMULA.

The player starts with the Flashlight OFF item. Using it calls common event Flashlight ON.

Flashlight ON common event works as follows:

◆If:Flashlight OK to USE is ON
◆If:Battery ≥ 50
◆Text:None, Window, Bottom
: :The battery is dead.
◆Show Choices:Use a battery, Cancel (Window, Right, #1, #2)
:When Use a battery
◆If:Party has Battery
◆Change Items:Battery - 1
◆Control Variables:#0007 Battery = 0
◆Control Switches:#0014 Flashlight ON = ON
◆Change Items:Flashlight off - 1
◆Change Items:Flashlight on + 1
◆Plugin Command:Fire radius 150 #333333
◆Plugin Command:Flashlight on 8 20 #333333 1

:Else
◆Text:None, Window, Bottom
: :You are out of batteries.

:End

:When Cancel

:End

:End
◆If:Battery < 50
◆Plugin Command:Fire radius 150 #333333
◆Plugin Command:Flashlight on 8 20 #333333 1
◆Control Switches:#0014 Flashlight ON = ON
◆Change Items:Flashlight off - 1
◆Change Items:Flashlight on + 1

:End

:Else
◆Text:None, Window, Bottom
: :There is no need to use a flashlight here.

:End

This turns the Flashlight ON switch on, which is linked to Flashlight ON FORMULA common event.
That is a parallel event that works as follows:

◆Control Variables:#0007 Battery = Steps
◆If:Battery ≥ 50
◆Change Items:Flashlight on - 1
◆Change Items:Flashlight off + 1
◆Wait:30 frames
◆Plugin Command:Flashlight off
◆Plugin Command:Light radius 120 #63cdff
◆Wait:30 frames
◆Text:None, Window, Bottom
: :The flashlight battery has gone dead.
◆Show Choices:Use a battery, Cancel (Window, Right, #1, #2)
:When Use a battery
◆If:Party has Battery
◆Change Items:Battery - 1
◆Control Variables:#0007 Battery = Random 0..5
◆Change Items:Flashlight off - 1
◆Change Items:Flashlight on + 1
◆Play SE:Equip1 (90, 120, 0)
◆Wait:20 frames
◆Plugin Command:Fire radius #333333
◆Plugin Command:Flashlight on 8 20 #333333 1

:Else
◆Text:None, Window, Bottom
: :You are out of batteries.
◆Control Switches:#0014 Flashlight ON = OFF

:End

:When Cancel
◆Control Switches:#0014 Flashlight ON = OFF

:End

:End

Finally, when turning the flashlight off the Flashlight OFF common even is calledt:

◆Plugin Command:Flashlight off
◆Plugin Command:Light radius 120 #50a6ce
◆Change Items:Flashlight off + 1
◆Change Items:Flashlight on - 1
◆Control Switches:#0014 Flashlight ON = OFF


I realize this is a complicated problem.
I've really tried hard with it for days now, and it is holding up my project, but I just can't give up.

Anyway, if you had any feedback or suggestions, I would welcome them very much.

Thank you.
 

Status Gear Entertainment

Praised Adventurer
I was curious on something that involved step counts too. I asked a friend and he came up with this :
Code:
$gameParty._steps % 50 == 0 && $gameParty._steps > 0
upload_2018-6-5_22-57-44.png

Although this would be more appropriate for detecting whether it should be off, because if it's a multiple of 50 and the battery life is 50, this would be detecting when it's dead.

You could use it to indicate when the battery should be dead, that should give the same effect. You could also have the value only increment when some flag is true, if the battery is alive. This way, the battery is actually just some flag you set/unset when you charge it and when it dies.

But this alone will be able to check to see if you've taken 50 steps from when the flashlight switch is ON and if you wish to reset the steps to 0 use this
Code:
$gameParty._steps = 0;
which is used as a script function. Hoped this helped make everything easier for you! (glad)(icecream)
 

ddblue0

Villager
Xy$
0.20
Hi and thank you for this - I was just curious, does this store partial battery use? I was hoping to add a battery as a useful item in the game, and that might require keeping track of partial battery use.
 
Top