So, first things first, go to Common Events in your Database and create a common event that the torch item will call (we’ll get to the torch item in a moment). This first common event will activate when the player activated their torch. We want it to switch on or off with player input, and, we also want it to check if there is enough battery life to run the torch, otherwise, it won’t switch on.
To walk you through the sequence of events in the screenshot:
There is a conditional branch checking for a switch we called “Torch On”. This switch gets set to “on” if the torch is currently on and “off” if the torch is currently off. Below that is another conditional branch checking if another switch which we called “Torch Dead” is off. This “Torch Dead” switch determines if there is battery power left in the torch or not. If there is no battery power left in the torch, this switch turns on, and if there is still battery power left in the torch, this switch turns off.
So, if the switch “Torch On” is off (the torch is not currently on) and if the switch “Torch Dead” is off, the “Torch On” switch is toggled to “on” (because you are switching the torch on) and we call the CGMZ Light Effects plugin command to set the light to the player. You can use other plugins for this, or do it without plugins, but we won’t discuss that here. In our common event, we also added a sound effect to play when this happens, to make a sound when the torch goes on, a click, y’know? But it’s optional.
Anyway, this “Torch Dead” conditional branch has an else branch, as in if the “Torch Dead” switch is on (if there is no more battery power in the torch), we show a message saying that the torch’s battery is dead…and the torch, obviously, is not switched on. You can do whatever you like here.
In the main “Torch On” conditional branch, there is also an else branch which checks if the torch is currently on. So, if the “Torch On” switch is “on” (the torch is currently on), the “Torch On” switch is set to “off” and the player light is removed. We also have an optional sound effect here.
So, that’s it for the main torch effect which will be called whenever the player activates the torch item.