I'm seeing some weird behavior where, if
setvar()
changes the default value of a variable, and the user has no custom value for that variable, then
getvar()
does not pick up the new default value immediately.
Here are my test scripts:
Code:
// alice.ash
import <zlib.ash>
string owner = 'Alice';
string owner_color = '#00ffff';
string dog_default_name = 'Ace';
string var_name = 'test_dogname';
print(`I am {owner}. I want to name my dog '{dog_default_name}'.`, owner_color);
print_html(`- <tt>vardefaults['{var_name}'].val == '{vardefaults[var_name].val}'</tt>`);
print_html(`- <tt>vars['{var_name}'] == '{vars[var_name]}'</tt>`);
print_html(`- <tt>getvar('{var_name}') == '{getvar(var_name)}'</tt>`);
setvar(var_name, dog_default_name);
print_html(`I called <tt>setvar('{var_name}', '{dog_default_name}')`);
print_html(`- <tt>vardefaults['{var_name}'].val == '{vardefaults[var_name].val}'</tt>`);
print_html(`- <tt>vars['{var_name}'] == '{vars[var_name]}'</tt>`);
print_html(`- <tt>getvar('{var_name}') == '{getvar(var_name)}'</tt>`);
print(`----- Good bye, {owner}! -----`, owner_color);
Code:
// bob.ash
import <zlib.ash>
string owner = 'Bob';
string owner_color = '#ffcc99';
string dog_default_name = 'Bella';
string var_name = 'test_dogname';
print(`I am {owner}. I want to name my dog '{dog_default_name}'.`, owner_color);
print_html(`- <tt>vardefaults['{var_name}'].val == '{vardefaults[var_name].val}'</tt>`);
print_html(`- <tt>vars['{var_name}'] == '{vars[var_name]}'</tt>`);
print_html(`- <tt>getvar('{var_name}') == '{getvar(var_name)}'</tt>`);
setvar(var_name, dog_default_name);
print_html(`I called <tt>setvar('{var_name}', '{dog_default_name}')`);
print_html(`- <tt>vardefaults['{var_name}'].val == '{vardefaults[var_name].val}'</tt>`);
print_html(`- <tt>vars['{var_name}'] == '{vars[var_name]}'</tt>`);
print_html(`- <tt>getvar('{var_name}') == '{getvar(var_name)}'</tt>`);
print(`----- Good bye, {owner}! -----`, owner_color);
And here is my gCLI output in a new KoLmafia session:
Rich (BB code):
> alice.ash
I am Alice. I want to name my dog 'Ace'.
- vardefaults['test_dogname'].val == ''
- vars['test_dogname'] == ''
- getvar('test_dogname') == ''
I called setvar('test_dogname', 'Ace')
- vardefaults['test_dogname'].val == 'Ace'
- vars['test_dogname'] == ''
- getvar('test_dogname') == 'Ace'
----- Good bye, Alice! -----
> alice.ash
I am Alice. I want to name my dog 'Ace'.
- vardefaults['test_dogname'].val == 'Ace'
- vars['test_dogname'] == 'Ace'
- getvar('test_dogname') == 'Ace'
I called setvar('test_dogname', 'Ace')
- vardefaults['test_dogname'].val == 'Ace'
- vars['test_dogname'] == 'Ace'
- getvar('test_dogname') == 'Ace'
----- Good bye, Alice! -----
> bob.ash
I am Bob. I want to name my dog 'Bella'.
- vardefaults['test_dogname'].val == 'Ace'
- vars['test_dogname'] == 'Ace'
- getvar('test_dogname') == 'Ace'
I called setvar('test_dogname', 'Bella')
- vardefaults['test_dogname'].val == 'Bella'
- vars['test_dogname'] == 'Ace'
- getvar('test_dogname') == 'Ace'
----- Good bye, Bob! -----
> bob.ash
I am Bob. I want to name my dog 'Bella'.
- vardefaults['test_dogname'].val == 'Bella'
- vars['test_dogname'] == 'Bella'
- getvar('test_dogname') == 'Bella'
I called setvar('test_dogname', 'Bella')
- vardefaults['test_dogname'].val == 'Bella'
- vars['test_dogname'] == 'Bella'
- getvar('test_dogname') == 'Bella'
----- Good bye, Bob! -----
When
bob.ash
is executed for the first time,
getvar('test_dogname')
returns 'Ace' even after calling
setvar('test_dogname', 'Bella')
. But when
bob.ash
is executed again,
getvar('test_dogname')
returns 'Bella' as expected.
I discovered this while investigating a bug in Philter (formerly OCD-Cleanup, forked from OCD Inventory Control). Philter (and OCD Inventory Control) sets the default value of
BaleOCD_DataFile
to the current player's name:
Code:
setvar('BaleOCD_DataFile', my_name());
setvar('BaleOCD_StockFile', my_name());
When you run OCD for player A, it sets the default value to 'A', meaning it would use
OCDdata_A.txt
. If you logged into another account B and executed OCD, the default value would be changed to 'B', but
getvar()
would still return 'A', causing OCD to purge B's inventory using
OCDdata_A.txt
.
What is causing this? I suspect that it has something to do with a
static
variables, since this behavior only occurs when
bob.ash
is executed for the first time in the current KoLmafia session.
Could this be looked into? I could avoid this behavior on Philter's side by not using
my_name()
as the default value, but I'm open to other ideas.