Save Variables?

King James

Villager
Member
Joined
May 31, 2014
Messages
20
Reaction score
2
First Language
German
Primarily Uses
Hey,

so I recently run into a problem with variables. Im currently making a horror game and it uses a latern and a flashlight. everything is working fine, even adding stuff into the latern to refresh it (it can die in my game?). My problem is when I switch from the flashlight to the latern, its always on 100%, but I want to save/memories the variable were it was before I turned on the flashlight and when im turning the latern on again, it should save the last variable.

for example: Im running around for a while with the latern and its kinda dieing/going out?, because its at 10-20%. so im gonna switch to the flashlight and after im done with it, im switching back to the latern and its back to 100%. wut?!

I have tried so many things .... nothing is working. The best try was when the latern reached 25% it kinda saved the variable. u saw the full latern for 1s then it went back to 25%, but thats still bad.

Here are some screenshots of my events. sry it is in german, but I think you will still understand it. Maybe its so simple.. that my brain cant handle :p



Note: Item Taschenlampe = Item Flashlight = An Event to see invisible Objects
Laternen ÖL = Latern Oil = Determines the Latern Life
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,288
Reaction score
7,636
First Language
German
Primarily Uses
RMMV
That is because your first command in the lantern life sets the variable to 100.

If you want to keep the last value, you need to erase that command to keep the previous number active.
 

Blackyu

Professional Procrastinator
Veteran
Joined
Jul 10, 2016
Messages
110
Reaction score
335
First Language
French
Primarily Uses
RMVXA
Well, apart from what @Andar said (because I just checked recent answers), I'm not sure that this system can work with only one variable that is supposed to store both the Lantern's life AND the Flashlight's (Or maybe you aren't done programming a separate mechanism for the Flashlight).
Also, you might want to set the Lantern/Flashlight's maximum life to 255 instead of 100, as the maximum opacity is 255 and you can't decrease opacity by 2,55 every time your Lantern Oil decreases by 1.
If you're using Khas Awesome Light Effects for VX Ace (and I think that's the case), you can use a system like this :

Condition : Switch[isLantern] is ON :
Wait 2 frames
Variable[LanternOil] = Variable[LanternOil] - 1
Condition : Variable[LanternOil] == 255 :
{Adequate Khas ALE script that sets the opacity to 255}​
Condition : Variable[LanternOil] == 238 :
{Adequate Khas ALE script that sets the opacity to 238}
#(Since 255 is 15 * 17, progressively decreasing by 17 is the most fluid 255-to-0 opacity fade out if you don't want to do it 1 by 1.)​
Condition : Variable[LanternOil] == 221 :
{Scripiddy script}
{-|-ETC-|-}

Condition : Variable[LanternOil] == 0 :
{The Script, again. Opacity is 0, so the lantern is drawn on-screen but isn't shown}
Switch[LanternDied] set to ON
Else : #(Which means Switch[isLantern] is OFF)
Wait 2 frames
Variable[FlashlightBatteries] = Variable[FlashlightBatteries] - 1
Condition : Variable[FlashlightBatteries] == 255 :
{Adequate Khas ALE script that sets the opacity to 255}​
Condition : Variable[FlashlightBatteries] == 238 :
{Moar Script Plz}​
Condition : Variable[FlashlightBatteries] == 221 :
{You Get It}
{-|-ETC-|-}

Condition : Variable[FlashlightBatteries] == 0 :
{Last Script :'D}
Switch[FlashlightDied] set to ON
As you can see, this system only uses two variables (One for each required power source), a switch that determines if the player is currently using the Lantern or the Flashlight, and I also added two optional switches that are ON when the Lantern runs out of Oil or the Flashlight's batteries die. It's kinda long, but it works.

There might be a way more efficient way to draw an opacity value based on a variable, but it requires more knowledge in Scripting than I possess. (And I don't possess a lot of knowledge about it tbh)
Maybe in the script box, you can set an in-script variable (a thing such as the variable 'l' used in Khas ALE to store the Lantern object) that can be equal to a Global Variable (which are the program's variables we know and love), and thus use the in-script variable to replace the first integer number as 'opacity' argument in the script, but it gets complicated and I'd already have too much trouble explaining it in my mother tongue, so I'm not even trying in English. xD
 

King James

Villager
Member
Joined
May 31, 2014
Messages
20
Reaction score
2
First Language
German
Primarily Uses
That is because your first command in the lantern life sets the variable to 100.

If you want to keep the last value, you need to erase that command to keep the previous number active.
Without it the System wouldnt know how much life there is. Tried it before and the lantern goes on for ever.

Well, apart from what @Andar said (because I just checked recent answers), I'm not sure that this system can work with only one variable that is supposed to store both the Lantern's life AND the Flashlight's (Or maybe you aren't done programming a separate mechanism for the Flashlight).
Also, you might want to set the Lantern/Flashlight's maximum life to 255 instead of 100, as the maximum opacity is 255 and you can't decrease opacity by 2,55 every time your Lantern Oil decreases by 1.
If you're using Khas Awesome Light Effects for VX Ace (and I think that's the case), you can use a system like this :

Condition : Switch[isLantern] is ON :
Wait 2 frames
Variable[LanternOil] = Variable[LanternOil] - 1
Condition : Variable[LanternOil] == 255 :
{Adequate Khas ALE script that sets the opacity to 255}​
Condition : Variable[LanternOil] == 238 :
{Adequate Khas ALE script that sets the opacity to 238}
#(Since 255 is 15 * 17, progressively decreasing by 17 is the most fluid 255-to-0 opacity fade out if you don't want to do it 1 by 1.)​
Condition : Variable[LanternOil] == 221 :
{Scripiddy script}
{-|-ETC-|-}

Condition : Variable[LanternOil] == 0 :
{The Script, again. Opacity is 0, so the lantern is drawn on-screen but isn't shown}
Switch[LanternDied] set to ON
Else : #(Which means Switch[isLantern] is OFF)
Wait 2 frames
Variable[FlashlightBatteries] = Variable[FlashlightBatteries] - 1
Condition : Variable[FlashlightBatteries] == 255 :
{Adequate Khas ALE script that sets the opacity to 255}​
Condition : Variable[FlashlightBatteries] == 238 :
{Moar Script Plz}​
Condition : Variable[FlashlightBatteries] == 221 :
{You Get It}
{-|-ETC-|-}

Condition : Variable[FlashlightBatteries] == 0 :
{Last Script :'D}
Switch[FlashlightDied] set to ON​
ill try this later. ill give you feedback.

EDIT: nope, doesnt work at all =/ and my flashlight actually doesnt have batteries of something like that. tried it, but wasnt fun and ruined the immersion in my game.
Tried some methods to kill the Lantern, but nothing worked. Does nobody have an answer to this?​
 
Last edited:

Blackyu

Professional Procrastinator
Veteran
Joined
Jul 10, 2016
Messages
110
Reaction score
335
First Language
French
Primarily Uses
RMVXA
There wouldn't be any reason why your Lantern isn't dying. When you take the Lantern, it's supposed to call Common Event 003 (Laterne), which proceeds to call C. Event 004 (Latern Life) : sets your Oil Variable to 100, turns ON switch Laterne Öl, and shows the Lantern at max opacity if it's equal to 100. Due to Laterne Öl being on, your Parallel Process C.Event is indeed launched, which means there must be a problem, either in the way you call C.Event 003 in the first place, or the way you've programmed C.Event 006. Could I get a screenshot of the new code, since you've modified it from the first screenshots ?
 

King James

Villager
Member
Joined
May 31, 2014
Messages
20
Reaction score
2
First Language
German
Primarily Uses
it is dying. all works perfect. my only problem is, when the lantern is for example at 20% and the light is almost out (you as the player see almost nothing anymore). So you would refill the Lantern. Works perfect too. But, since im having invisible Objects (only visible while the flashlight is on). You would in every Map switch to the flashlight as a player to see if there are any hidden items. After I switched from the Flashlight, while my Lantern has like 20% life left, to the Lantern again suddenly it is at 100% again. Im working on it for hrs ... every single solution isnt working ...
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,288
Reaction score
7,636
First Language
German
Primarily Uses
RMMV
Without it the System wouldnt know how much life there is. Tried it before and the lantern goes on for ever.
You misunderstood - you need to set the value, but not at that place.
For example in that event you first set the value to 100, and then make a conditional branch if it is 100 - it will always be 100 at that moment, because you set it to 100 a moment before and thereby the conditional branch is always true - and therefore not needed, because it can never be below 100 at that moment.

Your entire structure is rather convoluted, it would be better if you streamline the logic structure
 

King James

Villager
Member
Joined
May 31, 2014
Messages
20
Reaction score
2
First Language
German
Primarily Uses
You misunderstood - you need to set the value, but not at that place.
For example in that event you first set the value to 100, and then make a conditional branch if it is 100 - it will always be 100 at that moment, because you set it to 100 a moment before and thereby the conditional branch is always true - and therefore not needed, because it can never be below 100 at that moment.

Your entire structure is rather convoluted, it would be better if you streamline the logic structure
Im always working this way. Dunno why :p
Could you explain me then the right way or show me? because I tried everything I could to solve it, but I clearly failed. :(
Would really appreciate your help.
 

Jono99

Veteran
Veteran
Joined
May 8, 2015
Messages
76
Reaction score
17
First Language
English
Primarily Uses
RMVXA
@King James What you need to do is have variable 7 (Lantern oil) set to 100 somewhere else in the code, somewhere where it will only run once. I'll show you later, when I can.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Ami
What do you think about the Wood Bridge inside of Volcano?
Yet another gaming question, i'm currently playing Last of Us 2 and want to get another game to play next but can't decide between Ghost of Tsushima, Miles Morales & Jedi Fallen Order. After the latest mandalorian i AM on a star wars kick, but i also LOVED the last spiderman game that prequels Miles Morales. Ghost of Tsushima is the bottom of my list but i heard it was AWESOME. Just want a good story & fun gameplay.
I checked out Genshin Impact gameplay out of curiosity. I can't believe it's available as a mobile game too. Smooth animation, great music, and stellar sound effects (the ambient sounds are pretty detailed).

I'm flabbergasted to see games have becoming more and more advanced. Maybe also because I'm oblivious to current trend for a long time, it almost feel like I'm being sent into distant future. xD
xDRAGOONx wrote on WaywardMartian's profile.
Your artwork is amazing!!!
:ewat:
Stream will be live shortly with a session of the Interactive Text Adventure! Feel free to drop by!

Forum statistics

Threads
105,669
Messages
1,015,412
Members
137,344
Latest member
Zindasan0078
Top