pass a variable to another script

ki77bot

Member
How can I pass a particular variable (for instance a certain item) from one script to another?

Cheers,
ki77bot.
 
use set_property() and get_property() to save the variable as a preference.
Are these functions documented anywhere? I'm interested in storing data inbetween calls to a script, and this could potentially allow me to do that in a relatively clean way, but I need to know exactly how they're used and exactly what issues might arise as a result.
 

ki77bot

Member
Yep, they are documented, but unfortunately not very thouroughly (yet?).

KoLmafia Wiki

But since some $%&§$%§& morons put some attacking html.scripts there you might have to have to ignore some warnings to get there (depending on your browser).

Cheers,
ki77bot.
 
Yep, they are documented, but unfortunately not very thouroughly (yet?).

KoLmafia Wiki

But since some $%&§$%§& morons put some attacking html.scripts there you might have to have to ignore some warnings to get there (depending on your browser).

Cheers,
ki77bot.
Searching for set_property there yields nothing but red links.
 

Alhifar

Member
Simply use them as set_property( string prop , string set_to ) and get_property( string prop )
set_property returns void, get_property returns a string of what is in the property.
 

Bale

Minion
string set_property(string prop, string set_to)
string get_property( string prop )

examples of use:
Code:
time_soaked_today = to_int( get_property("_hotTubSoaks") );

if( get_property("switchEquipment") == "false")
     set_property("switchEquipment", "true");
Note that properties are always strings, even if you want to use them as booleans or integers. I've made a few mistakes by forgetting that.
 

Alhifar

Member
According to ashref, set_property() is a void. I can't really think of any sensible return value for it in any case.
 

Veracity

Developer
Staff member
The usual return value would be the previous value of the variable. With that, using the new "_" convention (variables starting with that get reset at rollover), you could do this:

Code:
if ( set_property( "_prop", "true" ) != "true" )
{
    ... executed only if _prop was not true. It now is true.
}
 

Bale

Minion
That sounds like a nice idea actually. Do you want to add a return value for set_property() in case anyone desires to do that?
 

ki77bot

Member
So, I tried out a few things now, but bviously I am doing something wrong.

My guess is that I need to convert the particular variable to a string before storing it in prefs.txt with set property ().

Well, to get a bit more precise, here is what I intend to do:

My breakfast script is checking on drink-mixing capabilities, based on what skills particular character has, it offers different solutions as what to drink.

All of those solutions are stored in 'item drink', so I can consume that. The 'good night' script should use the same drink. So I want to pass the drink item to the other script...

Could someone give a hint what I need to do?

Cheers,
ki77bot.
 

mredge73

Member
ok
on you regular script you can do this:

Code:
item goodnightdrink= something;//whatever you want to drink on good night
set_property("ki77bot's good night drink", goodnightdrink.to_string());

on you good night script:

Code:
item goodnightdrink= get_property("ki77bot's good night drink").to_item();
overdrink(1, goodnightdrink);

I would not use the underscore in this situation because _property clears whenever you exit mafia, not at rollover. I do not think that is what is intended but that is what happens.
 

ki77bot

Member
Allright, thanks a lot, I didn't know how to handle the transformation into a string and back into an item...

Cheers,
ki77bot.

Edit: Just tried that out, works great...
 
Last edited:
Top