CLI to ASH, am I doing it right?

CLI to ASH, am I doing it right? [New script version up]

I decided to take a stab in the dark at making an ash script, and here's what I've gotten.
I'll also include the cli script as well, so you can compare and see what I was trying to do.

EDIT: Alrighty, I changed the script as pertaining to Theraze's recommendations, now how does it look?
 

Attachments

  • Item_Farming_Duckey.txt
    488 bytes · Views: 42
  • Isotope_Grabbing.ash
    2.3 KB · Views: 32
Last edited:

Theraze

Active member
One potential problem... you check for <240 Phat Loot and >240 Phat Loot... but if you somehow end up with exactly 240 after, you're screwed in an infinite loop.

Lines like this:
cli_execute("use 2 milk of magnesium");
can also be done in ash, like this:
use(2, $item[milk of magnesium]);

A note... if you use adventure, it will repeat until it actually costs an adventure. If you use adv1, it will attempt one adventuring session. So adventure(my_adventures(), $location) will use up all your adventures. adv1($location, my_adventures(), "") may or may not. :)

Believe instead of this:
cli_execute("mallsell " +(item_amount($item[Lunar Isotope])) +" Lunar Isotope [[@] 350]");
you can again use ASH:
put_shop(350, 0, $item[Lunar Isotope]);
which puts all of your current Lunar Isotopes into the mall at 350 meat with no limit.

Same problem on ode as phat loot... checks for under 240, checks for over 240, never looks at 240.

Mentioned it above with use, but there's also eat, drink, and overdrink commands in ASH. :)
 
One potential problem... you check for <240 Phat Loot and >240 Phat Loot... but if you somehow end up with exactly 240 after, you're screwed in an infinite loop.

Lines like this: cli_execute("use 2 milk of magnesium");
can also be done in ash, like this: use(2, $item[milk of magnesium]);

A note... if you use adventure, it will repeat until it actually costs an adventure. If you use adv1, it will attempt one adventuring session. So adventure(my_adventures(), $location) will use up all your adventures. adv1($location, my_adventures(), "") may or may not. :)

Believe instead of this: cli_execute("mallsell " +(item_amount($item[Lunar Isotope])) +" Lunar Isotope [[@] 350]");
you can again use ASH: put_shop(350, 0, $item[Lunar Isotope]);
which puts all of your current Lunar Isotopes into the mall at 350 meat with no limit.

Same problem on ode as phat loot... checks for under 240, checks for over 240, never looks at 240.

Mentioned it above with use, but there's also eat, drink, and overdrink commands in ASH. :)

Well, thank you for that!
I actually did not know about the ash commands, I was going off of the guide on the wiki, the Scripting for Dummies here.

I'll get right on editing that in, and uploading a new version of the script (after dinner).

To check if it's equal to 240, should I have something like:
Code:
if(have_effect($effect[Ode to Booze]) < 240)
	repeat {wait(5); refresh_status();}
	until (have_effect($effect[Ode to Booze]) >= 240);
for both ode and phat loot?

And, for the adventuring, I should do
Code:
while( my_adventures() > 0 )
{
	adventure(my_adventures(), $location[Hamburglaris Shield Generator]);
}
instead of
Code:
while( my_adventures() > 0 )
{
	int temporaryAdvCounter = my_adventures();

	## Use a single adventure. Note, non-combat MAY NOT use an actual adventure.
	adventure( 1 , $location[Hamburglaris Shield Generator] );

	## See if that adventure actually took an adventure.
	if (temporaryAdvCounter > my_adventures())
	{
		## Our adventures decreased. Therefore this did take an adventure.
		adventureCounter = adventureCounter + 1;
	}
 
	print ("Ok, done with adventure " +adventureCounter +" of " +adventuresToday);
}
?
 
Last edited:

Theraze

Active member
Yep to both. As long as you're sure you'll end up with 240+ turns of the effect when done. If you aren't sure, you could do something more like this for your buffing:
int buffturns = have_effect($effect[Ode to Booze]);
if(buffturns < 240)
repeat {wait(5); refresh_status();}
until (buffturns > have_effect($effect[Ode to Booze]));
Basically, if you have less than 240 turns of Ode to Booze, wait until the amount of turns you have goes up. This will stop even if your buff only gets you to 130 turns of Ode, or 230 turns of ode, or... whatever you get to.
 
Thank you again! I shall now run my script and reap the benefits.

Yay!
It gave me a few string errors, so I mucked about in the wiki a bit, and fixed some silly little things.
 

Winterbay

Active member
If you want to make sure that your script runs without "running" it everytime you can use the "verify" command from the CLI (i.e. verify scriptname).
 

Donavin69

Member
Since this thread is already here, I figured I would post my question to it. I often use cli_execute("try; ...") is there an equivalent ASH for the 'try' option in the CLI?
 

Donavin69

Member
"try" without "finally" is pointless (005_Test.ash, line 6)

Nevermind :)

so, ASH equivalent of:
try; acquire 6 milk of magnesium
.
.
try {retrieve_item(6, $item[milk of magnesium]);} finally {}

(I had 5, so to test, I needed more than 5)
 
Last edited:

Bale

Minion
You don't need try in that example. I'd do it like this:

PHP:
if(!retrieve_item(6, $item[milk of magnesium]))
   print("Only have "+ item_amount( $item[milk of magnesium] ) + " Milks.");
 

slyz

Developer
If you don't want to give the warning, you can simply do
PHP:
if( retrieve_item(6, $item[milk of magnesium]) ) {}

I think that the script aborting or a function returning returning prematurely because retrieve_item() or any other boolean function returned false is a bug, or at least unwanted behavior. The above is a workaround for this kind of situation, though.
 

Theraze

Active member
And using jason's standard if () {} logic, it should also be simplifiable as:
Code:
!retrieve_item(6, $item[milk of magnesium]) );
 

Veracity

Developer
Staff member
the script aborting or a function returning prematurely because retrieve_item() or any other boolean function returned false is a bug, or at least unwanted behavior.
Used to be, boolean functions didn't necessarily return something useful. However, after somebody - you, I thought - made them return meaningful values. In particular, if retrieve_item() returns false, that is not a "bug". It is an indication that it failed to retrieve the items that you requested it to retrieve. Perhaps you ran out of meat. Perhaps you did not have the appropriate options checked to get the items. Ah. You are saying that it is a "bug" for scripts to not check return values - not that it is a "bug" for retrieve_item() to return false. I agree.

In any case, if your script has told KoLmafia to retrieve 6 of item X, presumably it intends to use 6 of items X. If KoLmafia fails to retrieve them, in general, I believe it exactly correct to abort the script at that time. Now, perhaps you really don't care if it got all of the items and have special code to actually use the number of items that WERE retrieved - or perhaps you have special code to detect failure when you try to use the items, or something. In that case, by all means - ignore the return result from retrieve_item, as slyz suggests, but be prepared to handle things later, when you don't have the items in your inventory that you were expecting.
 

Donavin69

Member
Often times I do want to do something if it wasn't successful, but not always, having a way to do something in the cases when you don't care is good...

One of the places that I use this format is for a stock list, I care that it didn't get the item, but I want it to continue to the next one...

The
PHP:
if (retrieve_item(qty, item)) {}
seems to do exactly what I was looking for, the same thing I was doing with:
PHP:
cli_execute("try; acquire "+to_string(qty)+" "+to_string(item));
but the code looks cleaner, and should be less system intensive.
 

Donavin69

Member
What is the order of processing in complex if statements

If ((FALSE) && (FALSE) && (TRUE))

would the second and third test be evaluated?

Would this try to eat the spaghetti, even if it had the trophy, or didn't have enough consumption space?
PHP:
if ((!contains_text(installed, "Platinum Skull")) 
   && (fullness_limit() - my_fullness() > 6)
   && (eat(1, $item[spaghetti with Skullheads]))) {}
 

slyz

Developer
Maybe I should start a new bug report/feature request for this.

Here is an example of what I mean by "function returning prematurely":
PHP:
boolean test()
{
	print( "start test" );
	retrieve_item( 1, $item[ Xlyinia notebook ] );
	print( "end test" );
	return true;
}

void main()
{
	test().print();
}
will result in:
Code:
> call test.ash

start test
[color=red]You need 1 more Xlyinia's notebook to continue.[/color]
false
It looks like a problem with ASH to me. The same happens with adventure() for example, and this is why scripters have to capture its return value.

Checking if retrieve_item() returned false and aborting the script if needed should be the scripter's job. Having a function returning prematurely could upset the rest of the script without dealing with the problem, if the scripter doesn't capture the return value.

EDIT: it doesn't happen with user-defined functions apparently:
PHP:
boolean false_function()
{
	return false;
}

boolean test()
{
	print( "start test" );
	false_function();
	print( "end test" );
	return true;
}

void main()
{
	test().print();
}
will result in
Code:
> call test.ash

start test
end test
true
 
Last edited:

Theraze

Active member
That works the way I think it should... if the script writer doesn't want it to abort, they should capture the value either by using ! or if () {}. Certain things like retrieve_item and adventure should probably abort by default (current behaviour) if uncaptured. It's the job of the script writer to continue it if they want it to keep going even if it fails...

Believe that your trophy check should abort properly. Believe that as soon as it hits something that invalidates it, further processing will stop...
 
Top