Scripting changes in 7.2/7.3

Veracity

Developer
Staff member
I took a look at the ASH and CLI change history and compiled a list of changes that affect scripting. There were plenty of bug fixes, and some new CLI commands were added that you probably wouln't use in a script ("survival", for example), but the following might be of interest:

ASH:

1) int_to_string (and automatic coercion to strings) no longer puts commas in the result string.

2) Declaration with simultaneous initialization:

int var = 1;

3) There is a new data type: the "slot". This designates a place to wear a piece of equipment.

Valid slots:

hat
weapon
off-hand
shirt
pants
acc1
acc2
acc3
familiar

Functions that manipulate the "slot" type:

int slot_to_int( $slot[pants] )
slot int_to_slot( 6 );
string slot_to_string( $slot[pants] )
...automatic coercion to a string in a context that needs a string

item current_equipment( $slot[pants] );
boolean unequip_slot( $slot[acc2] );
boolean equip_slot( $slot[acc2], $item[toy train] );

4) You can ask KoLmafia how many of an item it can create with available ingredients.

int creatable_amount( $item[chef-in-the-box] )

CLI:

1) Outfit checkpoints:

checkpoint - saves current equipment set into a special checkpoint outfit
outfit checkpoint - restores to saved outfit.
 

macman104

Member
with the declaration and simultaneous initialization of variables, can you do that with multiple variables, or do you need to declare/initialize each one separately? would this work:
Code:
int num1, num2, num3 = 5, num4;
 

Tirian

Member
Yay, two more functions in TirianLib.ash can be retired! ;D

There are a few other changes that might affect scripts as well. I know that my Abridged Dictionary script broke in the last flurry of changes before 7.2 was released because some item locations were changed. (In my case, "Pirate Cove (in disguise)" became "Pirate Cove In Disguise".) I appreciate the change, and I needed to rework that script to take advantage of slots anyways.

Also, in the name of full disclosure, there is a scripting bug that has been biting me throughout all of the 7.2 development and testing phase that hasn't been stamped out yet (at least as far as I know, I haven't hit 7.3 too hard). If a script ends prematurely (either an error or the user hitting the "stop all" button in the middle or at least some script aborting commands), you may find that you cannot run any scripts at all. The interface and CLI window and debug logs won't give you any response, at best just a green blink and no action. If this happens to you, then you'll have to shut down KoLmafia and restart it to regain the power to execute scripts. If nothing else, it creates a powerful incentive to write scripts that work properly the first time, because the debugging phase can get uncomfortable in a hurry. :p
 
1) int_to_string (and automatic coercion to strings) no longer puts commas in the result string.
Though I personally don't need this anymore, I might in the future. Great change!

2) Declaration with simultaneous initialization:

int var = 1;
This was something I was really hoping for! It will aid in cleaning up my code quite a bit!

3) There is a new data type: the "slot". This designates a place to wear a piece of equipment.
Slots! Slots! very much usefull for those who want a time sword in their off hand!

4) You can ask KoLmafia how many of an item it can create with available ingredients.
hmm, I don't see myself using it soon, but I can definately see it being usefull.
 

Tirian

Member
(about CheckCreatableAmount)

[quote author=efilnikufecin link=topic=135.msg644#msg644 date=1146690822]
hmm, I don't see myself using it soon, but I can definately see it being usefull.
[/quote]

I just got through writing a nice routine that does some cooking and drinkmixing for you to blow your chef before you ascend. The "problem" is that if you absent-mindedly pull all the raw food out of your clan and issue a "create * knob sausage chow mein" command, you might end up with a blown chef and 80 blends of herbs and spices when you could have had 20 chow mein if you had asked for it specifically. A script like this can go towards insuring that you'll have at least something edible at the end.

Code:
boolean make_chow_mein(item chow)
{
	if (!have_chef()) return false;
	string to_make;
	int count;
	while (true)
	{
		count = creatable_amount(chow);
		if (count == 0) return true;
		if (count > 5) {to_make = "5 ";} else {to_make = "* ";}

		cli_execute("create " + to_make + chow);
		if (!have_chef()) return true;
	}
	return true;
}
 
Top