Using the right amount of potions, based on current adventures

I'm cutting out most of the script, here are what I think are the relevant bits:

Code:
int currentChorale = have_effect($effect[chorale of companionship]);
int currentPunctual = have_effect($effect[Stickler for Promptness]);
int currentPetting = have_effect($effect[heavy petting]);
int choraleShotsNeeded =ceil(to_float(my_adventures()-currentChorale)/20);
int petSprayNeeded = ceil(to_float(my_adventures()+8-currentPetting)/10);
int punctualPotionsNeeded = ceil(to_float(my_adventures()-currentPunctual)/30);

~eating, drinking, other stuff happens~

buy(petSprayNeeded, $item[knob goblin pet-buffing spray]);
use(petSprayNeeded, $item[knob goblin pet-buffing spray]);
use(punctualPotionsNeeded, $item[potion of punctual companionship]);
use(choraleShotsNeeded, $item[recording of Chorale of Companionship]);

I'd like it to use enough potions to have the buffs last through all my adventures, but it seems to be using only enough to last me part of the way through the day. I don't recall how many adventures I started the day with, but my hunch is that my script used enough based on that number, and not my post-consumption number. Would a refresh_status(); before the use of the potions solve this?
 

Winterbay

Active member
Well, as the snippet is set up you calulate petSprayNeeded before you have eaten, if you do it after instead it should use the number you want. Similar for the other ones.
 

Theraze

Active member
No, they shouldn't be above. No, you can define things anywhere (except in the middle of other lines... no
Code:
if (15 > (int advcount = my_adventures()))
but if you wanted to throw that int advcount on its own line wherever, that works. It's only importing, notifications, script naming, and a few other such things that explicitly need to be at the beginning. Even the location of the main() block doesn't matter.
 

Winterbay

Active member
The definition of the variable can stay at the top if you so desire, but the setting of the number need to be lower down to be actually correct, but in that case you have a "int variablename" at the top and then "variablename = value" further down.
 
Top