Take a look at my part collector script (in the Turn-Burning Scripts section), it has the necessary code for visiting Richard and parsing the actual part counts, which may be a better solution for you.
I just wanted it so I could double check to see if I really was overkilling each time without more sever hits.
Example:
int part_count = get_count();
#Using the session result should be pretty safe as long as the user isn't changing things while the script runs. Even then it will just abort.
while( something )
{
adventure( 1 in square );
assert( part_count+1 == get_count() );
part_count = get_count();
}
By the way, your script is what I'm using to parse richard's text and I'm really grateful for it. I just wanted something that would do the same thing as this code you wrote.
if(item_amount($item[hobo nickel]) != nickels) {
abort("You got a hobo nickel - adjust your combat strategy!");
}