Testing out ASH. Will this work?

Mystia

Member
I've had good experiences using cli_execute();, and now I'd like to move on to some more advanced things. Below, I've altered an existing script that runs entirely on cli_execute(); functions to one that uses a little more complexity

Old version:
Code:
cli_execute("cast * pastamastery");
cli_execute("mallsell * dry noodle");
cli_execute("cast 3 sugar");
cli_execute("mallsell 3 sugar sheet");
cli_execute("cast 20 leash");
cli_execute("acquire 21 Knob Goblin Nasal Spray");
cli_execute("use 21 Knob Goblin Nasal Spray");
cli_execute("acquire milk of magnesium");
cli_execute("acquire 15 twinkly wad");
cli_execute("use 15 twinkly wad");
cli_execute("acquire 19 blackberry schnapps");
cli_execute("drink 19 blackberry schnapps");
cli_execute("acquire 3 spooky hi mein");
cli_execute("use 1 milk of magnesium");
cli_execute("eat 3 spooky hi mein");
cli_execute("outfit Castle");
cli_execute("familiar leprechaun");
cli_execute("equip meat detector");
cli_execute("adventure * Giant's Castle");
cli_execute("autosell * heavy D, * Original G, * disturbing fanfic, * furry fur, * wolf mask, * awful poetry journal, * thin black candle, * chaos butterfly, * plot hole, * probability potion, * procrastination potion, * angry farmer candy, * giant needle, * Mick's IcyVapoHotness Rub, * rave whistle");
cli_execute("acquire 1 roll in the hay");
cli_execute("drink 1 roll in the hay");
cli_execute("use * Warm Subject gift certificate");
cli_execute("outfit Rollover");

New version:
Code:
cli_execute("cast * pastamastery");
cli_execute("mallsell * dry noodle");
cli_execute("cast 3 sugar");
cli_execute("mallsell 3 sugar sheet");
cli_execute("cast 20 leash");
cli_execute("acquire 21 Knob Goblin Nasal Spray");
cli_execute("use 21 Knob Goblin Nasal Spray");
cli_execute("acquire milk of magnesium");
cli_execute("use 1 milk of magnesium");
item Tastyfood() {
	item [int] Tastyfood;
	foreach key in $items[Hot Hi Mein, Cold Hi Mein, Sleazy Hi Mein, Stinky Hi Mein, Spooky Hi Mein]
		Tastyfood[count(Tastyfood)] = key;
	cheapest_first(Tastyfood);
	return Tastyfood[0];
}
retrieve_item(3, $item[Tastyfood])
eat(3, $item[Tastyfood]);
item Spleentastic() {
	item [int] Wadsyo;
	foreach key in $items[Twinkly Wad, Hot Wad, Sleaze Wad, Spooky Wad, Cold Wad, Hot Wad, Stench Wad]
		Wadsyo[count(Wadsyo)] = key;
	cheapest_first(Wadsyo);
	return Wadsyo[0];
}
retrieve_item(15, $item[Wadsyo])
use(15, $item[Wadsyo]);
boolean Breakfastbooze( The Ode to Booze )
{
    if ( !have_skill( The Ode to Booze ))
        return true;

    return ( use_skill( 1, The Ode to Booze ) );

    else ()
	return false;
}
cli_execute("acquire 19 blackberry schnapps");
cli_execute("drink 19 blackberry schnapps");
cli_execute("outfit Castle");
cli_execute("familiar leprechaun");
cli_execute("equip meat detector");
cli_execute("adventure * Giant's Castle");
cli_execute("autosell * heavy D, * Original G, * disturbing fanfic, * furry fur, * wolf mask, * awful poetry journal, * thin black candle, * chaos butterfly, * plot hole, * probability potion, * procrastination potion, * angry farmer candy, * giant needle, * Mick's IcyVapoHotness Rub, * rave whistle");
boolean Dinnerbooze( The Ode to Booze )
{
    if ( !have_skill( The Ode to Booze ))
        return true;

    return ( use_skill( 1, The Ode to Booze ) );

    else ()
	return false;
item Ghettodrinks() {
	item [int] Nightcap;
	foreach key in $items[a little sump'm sump'm, an evil little sump'm sump'm, around the world, blended frozen swill, calle de miel, ducha de oro, evil ducha de oro, evil horizontal tango, evil roll in the hay, fruity girl swill, fuzzbump,
horizontal tango, ocean motion, perpendicular hula, pink pony, rockin' wagon, roll in the hay, slap and tickle, slip 'n' slide, tropical swill]
		Nightcap[count(Nightcap)] = key;
	cheapest_first(Nightcap);
	return Nightcap[0];
}
retrieve_item(1, $item[Ghettodrinks])
drink(1, $item[Ghettodrinks]);
cli_execute("use * Warm Subject gift certificate");
cli_execute("outfit Rollover");

Now a lot of this was reverse engineered, so I don't exactly understand some of these, if they work at all.

1) The "Breakfastbooze" boolean, is that how I use that command? How would I refer to it later in the code, rather than repeating it as Dinnerbooze?
2) the "If/else" line in the Breakfastbooze boolean, I just kinda placed those there. Is that how that works?
3) Are the "Tastyfood", "Spleentastic", and "Ghettodrinks" variables done correctly?
4) If I ran this script on a character that had all the skills, outfits, and familiars mentioned in the script, would it run correctly?
 

Bale

Minion
I'm afraid there are a few problems. In an entirely different order from the way you asked those questions, I'll try to give some advice on your problems.

This is incorrect: $item[Tastyfood]

$item[] defines a constant, but Tastyfood() returns a variable which is of type item, so you can use Tastyfood without the item declaration. In other words, you can simply do this: retrieve_item(3, Tastyfood());. Tastyfood() is a function, not a variable so you need to put the set of parenthesis after it. Obviously the same goes for Ghettodrinks() and Spleentastic(), though you made an additional error by trying to use $item[Wadsyo] instead of Spleentastic().

cheapest_first() is not a mafia function. I assume you saw it in one of my scripts. You need to define the function in your script so copy it from the place where you saw it used.

Concerning Breakfastbooze(), you kinda completely blew the function, but I think you can forget about trying to define the function. Mostly those lines do nothing, so simply use these 2 lines instead:

Code:
   if(have_skill($skill[The Ode to Booze]))
      use_skill(1, $skill[The Ode to Booze]);
 
Last edited:

jasonharper

Developer
I'm not sure you're really headed in the right direction with this - choosing the cheapest out of a set of items is actually easier to do with CLI commands, yet you're doing lots of things with cli_execute() that are actually trivial to express directly in ASH.

You're defining (or at least attempting to define) several functions, such as Breakfastbooze, but never call them. Most of this code wouldn't actually do anything.

You're calling a function called cheapest_first() which isn't defined anywhere.

You don't seem to quite understand what $item[...] and similar forms do - these create constant values of the specified type, in exactly the same way that "cat" creates a constant string value, and 42 creates a constant integer value. So when you write something like $item[Tastyfood], you're trying to refer to a specific item with a name that matches 'Tastyfood' - and there is no such item, of course. This does NOT refer to a variable named 'Tastyfood' (you'd simply write Tastyfood in that case), nor does it refer to the value returned by a function named 'Tastyfood' (you'd write Tastyfood() in that case, with the parameters that the function needs - if any - between the parentheses).
 

Mystia

Member
I'm aware that many of these functions are better executed in cli_execute, however, I'm still trying to learn the coding, so it's easier to have something to compare it to.
I want others to know what I'm trying to do, rather than posting a bad script and saying "fixplz". Once I understand it a bit better, I'll be doing something a little more complex.
I'm also aware I have damn near no idea what I'm doing. I've got no previous coding experience, and the wiki isn't layman enough for me to fully understand the purpose of many aspects of this.

Bale, I saw cheapest_first in one of your scripts, I was not aware it had to be defined, so I didn't bother to look for the line that defined it.

Code:
{
   if(have_skill($skill[Pastamastery]))
         and(have_skill($skill[Transcendental Noodlecraft]))
            use_skill(5, $skill[Pastamastery]));
      use_skill(3, $skill[Pastamastery]);
}
cli_execute("mallsell * dry noodle");
{
   if(have_skill($skill[Summon Sugar Sheet]))
      use_skill(3, $skill[Summon Sugar Sheet]);
}
void cheapest_first (item [int] commodity) {
	int [item] price;
	foreach key in commodity
		if(historical_age(commodity[key]) >0.5)
			price[ commodity[key] ] = mall_price(commodity[key]);
		else
			price[ commodity[key] ] = historical_price(commodity[key]);
	sort commodity by price[value];
}


cli_execute("acquire 21 Knob Goblin Nasal Spray");
cli_execute("use 21 Knob Goblin Nasal Spray");
cli_execute("acquire milk of magnesium");
cli_execute("use 1 milk of magnesium");
item Tastyfood() {
	foreach key in $items[Hot Hi Mein, Cold Hi Mein, Sleazy Hi Mein, Stinky Hi Mein, Spooky Hi Mein]
		Tastyfood[count(Tastyfood)] = key;
	cheapest_first(Tastyfood);
	return Tastyfood[0];
}
retrieve_item(3, Tastyfood());
eat(3, Tastyfood());
item Wadsyo() {
	foreach key in $items[Twinkly Wad, Hot Wad, Sleaze Wad, Spooky Wad, Cold Wad, Hot Wad, Stench Wad]
		Wadsyo[count(Wadsyo)] = key;
	cheapest_first(Wadsyo);
	return Wadsyo[0];
}
retrieve_item(15, Wadsyo());
use(15 Wadsyo());
   if(have_skill($skill[The Ode to Booze]))
      use_skill(1, $skill[The Ode to Booze]);
cli_execute("acquire 19 blackberry schnapps");
cli_execute("drink 19 blackberry schnapps");
{
   If(have_skill($skill[Leash of Linguini]))
      use_skill(20, $skill[Leash of Linguini]);
}
cli_execute("outfit Castle");
cli_execute("familiar leprechaun");
cli_execute("equip meat detector");
cli_execute("adventure * Giant's Castle");
cli_execute("autosell * heavy D, * Original G, * disturbing fanfic, * furry fur, * wolf mask, * awful poetry journal, * thin black candle, * chaos butterfly, * plot hole, * probability potion, * procrastination potion, * angry farmer candy, * giant needle, * Mick's IcyVapoHotness Rub, * rave whistle");
   if(have_skill($skill[The Ode to Booze]))
      use_skill(1, $skill[The Ode to Booze]);
item Ghettodrinks() {
	foreach key in $items[a little sump'm sump'm, an evil little sump'm sump'm, around the world, blended frozen swill, calle de miel, ducha de oro, evil ducha de oro, evil horizontal tango, evil roll in the hay, fruity girl swill, fuzzbump,
horizontal tango, ocean motion, perpendicular hula, pink pony, rockin' wagon, roll in the hay, slap and tickle, slip 'n' slide, tropical swill]
		Nightcap[count(Nightcap)] = key;
	cheapest_first(Nightcap);
	return Nightcap[0];
}
retrieve_item(1, Ghettodrinks());
drink(1, Ghettodrinks());
cli_execute("use * Warm Subject gift certificate");
cli_execute("outfit Rollover");

-I tried taking the If(have_skill... line and kicking it up a notch in the first part.
What I'm trying for is "If you have pasta and transcendental, you cast noodles 5 times, if you have pasta and no transcendental, you cast it three times". Does that work?

-The void cheapest_first was from a script Bale made to compare mall prices, and hopefully fixes problems with the later part of the code.

-Does item(tastyfood..., Retrieve_item(tastyfood..., Eat(tastyfood... work now?
 

slyz

Developer
Code:
// these can be done by configuring the 'Ronin-clear' part of the Breakfast preferences:
//cli_execute("cast * pastamastery");
//cli_execute("cast 3 sugar");


// sorts the map of items by mall price, in ascending order.
item cheapest( item[int] itms ) {
	sort itms by ( mall_price(value) );
	return itms[0];
}

item Tastyfood() {
	item [int] Tastyfood;
	foreach key in $items[Hot Hi Mein, Cold Hi Mein, Sleazy Hi Mein,
                                           Stinky Hi Mein, Spooky Hi Mein]
		Tastyfood[count(Tastyfood)] = key;
	return cheapest(Tastyfood);
}

item Spleentastic() {
	item [int] Wadsyo;
	foreach key in $items[Twinkly Wad, Hot Wad, Sleaze Wad, Spooky Wad,
                                                              Cold Wad, Hot Wad, Stench Wad]
		Wadsyo[count(Wadsyo)] = key;
	return cheapest(Wadsyo);
}

// I removed the untradeable drinks from the list.
item Ghettodrinks() {
	item [int] Nightcap;
	foreach key in $items[a little sump'm sump'm, blended frozen swill,
                                           calle de miel, ducha de oro, fruity girl swill,
                                           fuzzbump, horizontal tango, ocean motion,
                                           perpendicular hula, pink pony, rockin' wagon,
                                           roll in the hay, slap and tickle, slip 'n' slide, tropical swill]
		Nightcap[count(Nightcap)] = key;
	return cheapest(Nightcap);
}

// You don't really need a main(), but just so you get the hang of declaring functions:
void main() {
	// this will put the items in your shop at 999,999,999 meat if you don't have any,
	// or without changing the price if you had some.
	put_shop( 0, 0, item_amount($item[dry noodle]), $item[dry noodle]);
	put_shop( 0, 0, item_amount($item[sugar sheet]), $item[sugar sheet]);

	// I let mafia satisfy with mall, so no need to buy first.
	use(1, $item[milk of magnesium]);
	
	eat(3, Tastyfood());
	// can be replaced by the following CLI command:
	// cli_execute("cheapest Hot Hi Mein, Cold Hi Mein, Sleazy Hi Mein,
	//						 Stinky Hi Mein, Spooky Hi Mein; buy 3 it; eat 3 it;");
	
        // You should have leftover turns of Ode, so check if you need to cast
	if ( have_effect($effect[Ode to Booze]) == 0 && have_skill($skill[The Ode to Booze]) )
		use_skill(1, $skill[The Ode to Booze]);
	
	drink(19, $item[blackberry schnapps]);
	
	use(15, Spleentastic());
	// can be replaced by the following CLI command:
	// cli_execute("cheapest Twinkly Wad, Hot Wad, Sleaze Wad, Spooky Wad, Cold Wad,
	//						           Hot Wad, Stench Wad; buy 15 it; use 15 it;");
	
	// Determine how many turns of Wasabi Sinuses you need, 
        // and use enough nasal sprays
	int numSprays = ceil( (my_adventures() - have_effect($effect[Wasabi Sinuses]) )/10.0 );
	use( numSprays , $item[Knob Goblin Nasal Spray]);

    // Same thing for Leash
	if ( have_skill($skill[Leash of Linguini]) ) {
        int numLeash = ceil( (my_adventures() - have_effect($effect[Leash of Linguini]) )/10.0 );
		use_skill(numLeash, $skill[Leash of Linguini]);
	}
	
	outfit("Castle");
	use_familiar($familiar[leprechaun]);
	equip($slot[familiar], $item[meat detector]);
	
	adventure(my_adventures(), $location[Giant's Castle]);
	
    // I was too lazy to convert that into ASH =)
	cli_execute { autosell * heavy D, * Original G, * disturbing fanfic, * furry fur,
					* wolf mask, * awful poetry journal, * thin black candle,
					* chaos butterfly, * plot hole, * probability potion,
					* procrastination potion, * angry farmer candy, * giant needle,
					* Mick's IcyVapoHotness Rub, * rave whistle
	}
	use( item_amount($item[Warm Subject gift certificate]), $item[Warm Subject gift certificate]);
	
	if ( have_skill($skill[Ode to Booze]) )
		use_skill(1, $skill[Ode to Booze]);
	
	drink(1, Ghettodrinks());
	// can be replaced by the following CLI command:
	// cli_execute("cheapest +fuzzbump, +tropical swill ; buy 1 it; use 1 it;");
}

A couple of tips:

- use ashref <function> in the gCLI to see what input/output an ASH function has, or simply to search for one (ashref shop for example).

- use verify myscript.ash, it will give you valuable info if something's wrong in your syntax.

EDIT: forgot a couple of braces.
EDIT2: meh, I tried to make the code not take up so much place by breaking lines, but I don't understand how the forum interprets spaces =)
 
Last edited:

Mystia

Member
That's very helpful, slyz. Thanks.
I'll be posting an updated version some time tonight if I have more questions.
 

slyz

Developer
It doesn't allow for checking historical_price() or mall_price() depending on the age though.
 
Or do the check, then call historical_price() in the sort -- by that point, everything with an outdated historical price will have been updated so it's not outdated any more.

Jason's solution is much nicer to read, though.
 
Top