Is it possible to get object's variable initial value?

breakmt

Member
Hello!
I doubt that it is possible, but anyway.
I have an object with variable, which I set in "Variable Definitions" window. Is there any way to get initial value of this variable?

Example:
Variable "hp" (health points) = 35 -> Instance changed this variable to 13 -> Now I want to reset it's value back to 35.
One way I see it's to keep 2 variables - hp_original and hp_current, but it would be a bit better if I could keep just one variable.

Thanks!
 
C

Catastrophe

Guest
Not really. That's basically what variables are for: storing data into RAM. If you change the variable, the old value has nowhere to go but to be ejected. There's tricks you can play in select circumstances to cut down (e.g. procedural generation allowing to "store" many things essentially in one variable), but this isn't really one of them. Your alternative is the way to go.
 

CloseRange

Member
yes you are pretty much forced to store both a min and a max variable.
There are tricks you can use if you really really need to worry about storage, mainly using bit-wise operators to store 2 variables in one.
Though that's way more complicated than just using 2 variables.
though I'd suggest shortening the names. My prefrence is to name them like this:
Code:
hpM = 35
hp = hpM
where M is a shorthand for max, so the max hp (or the original in this case)
 

Slyddar

Member
I always keep 2 variables when I need to restore values. I just add "_initial" as the variable name and keep the original value that way, as you've suggested. Works great, and it's a minor amount of memory required to hold it.
 

breakmt

Member
Thanks! I just worried that I missed some functionality, but now I'm sure that two variables approach is right
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Try storing event_type/event_number in variable definitions so that you can find the event number for "variable definitions" magic event and event_perform_object it on a blank instance to grab the data.
 
Top