Updating variables

Hugbert!

New member
How would I go about declaring a variable, and then having it update properly? As in, with this little ditty, it'll print my buffed moxie, use the tomato juice (changing my actual buffed moxie), and then print the same number again. I'd prefer it printed an accurate number the second time!

int moxie = my_buffedstat($stat[Moxie]);
print (moxie);
use(1, $item[tomato juice of powerful power]);
print (moxie);
 
I'm not an expert, but if ash scripting is anything like most languages, that code is setting moxie to the value of my_buffedstat($stat[Moxie]); at the time, not tying the variable to change with it. There may be some equivalent to an alias command, or you could just use the same call again.
 

Pazleysox

Member
I'm not an expert, but if ash scripting is anything like most languages, that code is setting moxie to the value of my_buffedstat($stat[Moxie]); at the time, not tying the variable to change with it. There may be some equivalent to an alias command, or you could just use the same call again.

That's correct.

Code:
int moxie = my_buffedstat($stat[Moxie]);  // [COLOR="#FFA500"]You're storing my_buffedstat($stat[Moxie]) in the intger called moxie[/COLOR]
print (moxie); // [COLOR="#FFA500"]here you're printing what it has found[/COLOR]
use(1, $item[tomato juice of powerful power]); // [COLOR="#FFA500"]This changes your moxie[/COLOR]
print (moxie);  // [COLOR="#FFA500"]You're printing the number stored in the integer again.[/COLOR]

Try this:
Code:
int moxiebefore = my_buffedstat($stat[Moxie]); // [COLOR="#FFA500"]This records before[/COLOR]
print ("My Moxie before: " + moxiebefore);
use(1, $item[tomato juice of powerful power]);
int moxieafter = my_buffedstat($stat[Moxie]); //[COLOR="#FFA500"]This records after[/COLOR]
print ("My Moxie after: " + moxieafter); 
int difference = moxieafter - moxiebefore; //[COLOR="#FFA500"]Lets make an integer to do some math for us[/COLOR]
print ("Total boost of " + difference + " moxie points");//[COLOR="#FFA500"]And here we see the difference that the tomato juice made[/COLOR]
Here's my output:
My Moxie before: 615
Using 1 tomato juice of powerful power...
You acquire an effect: Tomato Power (10)
Finished using 1 tomato juice of powerful power.
My Moxie after: 905
Total boost of 290 moxie points

Hope this helps.
 

lostcalpolydude

Developer
Staff member
Without any context for what you are trying to do, I suspect that you should be using my_buffedstat($stat[Moxie]) each time you need it instead of assigning it to a variable.
 

Pazleysox

Member
Looking at it again, you don't even need to make it an int.

print(my_buffedstat($stat[Moxie]));

will do the exact same thing. Just call it twice.

Code:
print(my_buffedstat($stat[Moxie]));
use(1, $item[tomato juice of powerful power]); 
print(my_buffedstat($stat[Moxie]));

The only reason I can think of storing it in an int is if you want to save the number, to recall it later, even if it's changed.
 

Crowther

Active member
How would I go about declaring a variable, and then having it update properly? As in, with this little ditty, it'll print my buffed moxie, use the tomato juice (changing my actual buffed moxie), and then print the same number again. I'd prefer it printed an accurate number the second time!

int moxie = my_buffedstat($stat[Moxie]);
print (moxie);
use(1, $item[tomato juice of powerful power]);
print (moxie);
To me it sounds like you want a function. This does what you want with little changes to your code.
Code:
int moxie() { return my_buffedstat($stat[Moxie]); }
print (moxie());
use(1, $item[tomato juice of powerful power]);
print (moxie());
 
Top