We have a large number of things that are coded to use 1). For example:
Code:
if ( responseText.contains( "You don't have the item you're trying to use." ) )
{
UseItemRequest.lastUpdate = "You don't have that item.";
KoLmafia.updateDisplay( MafiaState.ERROR, UseItemRequest.lastUpdate );
return;
}
This would be a user/script error.
Code:
if ( responseText.contains( "You've already got a familiar of that type." ) )
{
UseItemRequest.lastUpdate = "You already have that familiar.";
KoLmafia.updateDisplay( MafiaState.ERROR, UseItemRequest.lastUpdate );
return;
}
This seems like it is useless, but would harmless if we didn't stop your script; if your goal was to end up with the familiar in your terrarium, that has been achieved.
Code:
case ItemPool.HEY_DEZE_MAP:
// "Your song has pleased me greatly. I will reward you
// with some of my crazy imps, to do your bidding."
if ( !responseText.contains( "pleased me greatly" ) )
{
UseItemRequest.lastUpdate = "Your music was inadequate.";
KoLmafia.updateDisplay( MafiaState.ERROR, UseItemRequest.lastUpdate );
return;
}
break;
Similarly, this error is worth stopping your script for.
Code:
case ItemPool.CHATEAU_ROOM_KEY:
Preferences.setBoolean( "chateauAvailable", true );
// You hike up the mountain to Chateau Mantegna and try
// the key in various doors until you find the one it
// unlocks. It's quite a nice room!
if ( !responseText.contains( "you find the one it unlocks" ) )
{
UseItemRequest.lastUpdate = "You've already have a room at the Chateau Mantegna.";
KoLmafia.updateDisplay( MafiaState.ERROR, UseItemRequest.lastUpdate );
return;
}
break;
Again - does this need to stop your script? But it does.
Code:
case ItemPool.THUNDER_THIGH:
case ItemPool.AQUA_BRAIN:
case ItemPool.LIGHTNING_MILK:
{
// You can't learn anything else from this, so you just throw it away.
if ( !responseText.contains( "you just throw it away" ) )
{
return;
}
break;
}
This doesn't stop your script. It may also do the wrong thing, since it says "you just throw it away", but we don't remove it from inventory.
Code:
case ItemPool.ABSINTHE:
// "You drink the bottle of absinthe. It tastes like
// licorice, pain, and green. Your head begins to ache
// and you see a green glow in the general direction of
// the distant woods."
// "No way are you gonna drink another one of those
// until the last one wears off."
if ( !responseText.contains( "licorice" ) )
{
return;
}
break;
Here we simply return without comment if you are already under the influence.
I think 1) and 2) are the best choices:
1) for things that really should stop your script if not trapped
2) for things after which the script can continue with no harm, whether or not it is trapped
We currently have a lot of 1), even when the script might not need to be stopped, and 4), which will not stop the script but not let the script know it failed or let the user know that something unexpected/unnecessary happened.
Evaluating all the usable items that can fail and deciding whether the failure should be 1) or 2) or 3) and making it so seems like a project.
Let's start by considering the Dog Chow. If I understand, it gives your familiar experience?
Your script needs to detect the failure so it can be coded to not loop forever. But we have two kinds of script - CLI and ASH - and if we define a failed usage as "stop your script", a CLI script will, in fact, stop immediately. So will an ASH script that ignores the return value. But one which captures/tests the return value will continue.
If I have "use 1 Ghost Dog Chow" in my CLI script, do I really want to to stop the script if it fails (option 1)? Or do I want to see "your familiar isn't hungry enough" and continue (option 2)? Or do I want to not see a message and continue (option 3 or 4)?
I think 1 and 2 are the options:
1) See a message and stop the script if the your character state is unexpected after the failure
2) See a message and continue if things are actually fine: reading a skill book when you already have the skill, for example.
As I said, evaluating all use failures is a Project.
But for Dog Chow, do you want 1 or 2? As I said, keep the CLI script in mind. Does it need to stop if it fails to level a familiar?