cyrpt problem

mmmk

New member
so my question concerns:

Code:
void cyrpt()
{
	cli_execute("adventure * defiled nook");
	cli_execute("adventure * defiled cranny");
	cli_execute("adventure * defiled alcove");
	cli_execute("adventure * defiled niche");
}

i'm using kolmafia 8.5 and when it finishes each section, i get a "Nothing more to do here" message and it doesn't move on to the next portion of the script.

is there a way around this?

thanks in advance.  i'll be on vacation and might not see this for a few days.
 

cjswimmer

Member
try this:

Code:
void cyrpt()
{
	boolean OK;
	OK = cli_execute("adventure * defiled nook");
	OK = cli_execute("adventure * defiled cranny");
	OK = cli_execute("adventure * defiled alcove");
	OK = cli_execute("adventure * defiled niche");
}
 

peterbones

New member
Yeah, I often run into problems where I get kicked out of a script because mafia likes to do that.  I'm not sure of all the conditions (or if they're listed anywhere) it aborts under, but basically anytime an adventure fails and it's not handled by the calling script.  By fails, I mean you're out of adventures, too drunk, can't adventure at the place in question because of stats or its not existing... anything else?  And by not handled, I mean you just call the adventure command.  cjswimmer's fix is fine, personally I did this when I ran into that problem

Code:
    while( adventure( 1, $location[ Defiled Nook ] ) ){}
    while( adventure( 1, $location[ Defiled Cranny ] ) ){}
    while( adventure( 1, $location[ Defiled Alcove ] ) ){}
    while( adventure( 1, $location[ Defiled Niche ] ) ){}

but in the end it's all the same.  If you do an assigment or check with the output, your script won't abort.
 

arrggg

Member
Oh Snap! Looking at peterbones's example, I just realized you could hammer the servers hard, (and probably get banned in the process) if you did something like:
Code:
void main()
{
while( buy (1, $item[[i]Rare Item[/i]]) ){}
}

note: NEVER Run this code or any code like this.....
 

Tirian

Member
In fact, I don't think that cjswimmer's solution works. The problem is that, prior to version 7.1 or so, a location's failure to exist was an aborting condition for the adventure command, but now it isn't. I can't tell you why, but when the change happened, I remember sitting down with a piece of paper and calculting that it was a good change. :) There was a while when "adventure * defined alcove" would work poorly because it would incorrectly decrement your adventure count every time you bonked your head against the wall that used to lead to the alcove, but then the fix came in that counts adventures much better and so that command is now an infinite loop.

So, even if you're normally an "adventure *" kind of scripter, you have to make an exception for quests that end when a location disappears, like the cyrpt and the Road to White Citadel.
 

peterbones

New member
I did not realize this.  Does that mean that this code wouldn't work? I can't test it right now.
Code:
    if( adventure( my_adventures(), $location[ Defiled Nook ] ) ){}
    if( adventure( my_adventures(), $location[ Defiled Cranny ] ) ){}
    if( adventure( my_adventures(), $location[ Defiled Alcove ] ) ){}
    if( adventure( my_adventures(), $location[ Defiled Niche ] ) ){}

I thought it would.  Someday someone should probably update the reference manual with what conditions cause abortion (and what conditions return true/false, for that matter).  Anyway, the code I posted before works, though I haven't tested it under conditions like being out of adventures or too drunk, or not having the cyrpt quest, it should work AFAICT.

I highly suggest switching to adventure( my_adventures(), $location[ loc ] ) from adventure * loc if you're already in an ASH script, and I don't see any reason not to.

Oh, and arrggg, between that snippet and cheepest_of_the_bunch, are you sure you're not writing a mallbot :)
 

arrggg

Member
[quote author=peterbones link=topic=345.msg1921#msg1921 date=1155588541]
Oh, and arrggg, between that snippet and cheepest_of_the_bunch, are you sure you're not writing a mallbot :)
[/quote]

Na... I wanted "cheepest_of_the_bunch" so I don't have to search the mall manually upteen times looking for cheep food/drinks.

(But I really...really...really. want to run that code snippet... but then I would be banned, and that would be bad... but I really want to.)
 

Tirian

Member
[quote author=peterbones link=topic=345.msg1921#msg1921 date=1155588541]
I did not realize this. Does that mean that this code wouldn't work? I can't test it right now.
Code:
  if( adventure( my_adventures(), $location[ Defiled Nook ] ) ){}
  if( adventure( my_adventures(), $location[ Defiled Cranny ] ) ){}
  if( adventure( my_adventures(), $location[ Defiled Alcove ] ) ){}
  if( adventure( my_adventures(), $location[ Defiled Niche ] ) ){}

I thought it would.[/quote]

It might, but I bet you a nickle it won't. I think that your script runs the same underlying code as the CLI commands "adventure * defiled nook" et al.

One of the joys of the language is that it isn't quite mature. (It's also one of the hassles of the language.) I've been writing ASH scripts for about four months now, and it's really quite unrecognizable from what it was back then. I suspect it won't be recognizable two months from now. It's tough to nail down things in the manual with too much detail, because you never know when someone is going to subtly change a subtle point of functionality and not quite publicize it. I'd prefer that the manual was vague than wrong. If you want to know about stuff like that, you should ask in the forum.

Which you just did.

So far as I know, there is different logic for if you do adventure(1, ...) or do more than one adventure. Both will abort the entire script if you're out of adventures, drunk, or if your HP falls below the auto-abort level set in your preferences. Or if you hit the "Stop All" button, natch.

The multi-adventuring version will exit normally and return false if it used all the adventures you set and had conditions that were met. It will exit normally and return true if it used all of the adventures you set or at the point that all of the conditions are met. If you never use all of the adventures, then the script will be stuck in an infinite loop -- if that's a condition that can be identified, then it would probably make sense that the functional exit normally and return false under those conditions, and if Veracity is reading this and has a few free minutes she might do just that because we're talking about it. (That's the joy of the not-yet-mature language that I was mentioning.)

The one-round adventuring version will send one HTTP request to investigate the location, and then go on to resolve it if it is a combat or a choice adventure. I believe it will return true if it was a non-combat adventure or if it is a battle that you won and false if it is a combat you lost or a "you can't adventure here" message.
 

peterbones

New member
Both will abort the entire script if you're out of adventures, drunk, or if your HP falls below the auto-abort level set in your preferences.

Ah, well, right now I'm too drunk to continue.  So I try running this:

Code:
void main()
{
    if( adventure( my_adventures(), $location[ haunted pantry ] ) ){}
    print( "Handled all adventures." );
    if( adventure( 1, $location[ haunted pantry ] ) ){}
    print( "Handled 1 adventure." );
    adventure( 1, $location[ haunted pantry ] );
    print( "No handling." );
}

And I get this:

 > temp.ash
You are too drunk to continue.
Handled all adventures.
You are too drunk to continue.
Handled 1 adventure.
You are too drunk to continue.
Script aborted!

Which is what I was expecting.  Though it wasn't what I expected when I started scripting, it's a decent way to handle things.  If you're checking the result in the script, the script is expected to decide what to do if something goes wrong.  If not, then mafia aborts and lets the user decide.  And it works the same if you do a check/assignment on a cli_execute( "adventure * location" ), like cjswimmer suggested. I can't test it on the nonexistant locations right now (as mafia just tells me I'm too drunk) but I'd be surprised if it acted differently.

The not quite mature language may have changed while you weren't looking, Tirian.
 

macman104

Member
[quote author=Tirian link=topic=345.msg1924#msg1924 date=1155596147]So far as I know, there is different logic for if you do adventure(1, ...) or do more than one adventure. Both will abort the entire script if you're out of adventures, drunk, or if your HP falls below the auto-abort level set in your preferences. Or if you hit the "Stop All" button[/quote]I think it will abort the whole thing if you don't have something to accept the boolean it returns. Like if you just had in your code
Code:
adventure(1, $location[haunted pantry]);
and you were out of adventures. But if you put it in an if statement, then it should continue along just fine, assuming you had that if statement for some reason. Peterbones, I bet if you put your prints in the if statement, mafia would not print those, but still continue along.
 

Tirian

Member
[quote author=peterbones link=topic=345.msg1925#msg1925 date=1155598320]
The not quite mature language may have changed while you weren't looking, Tirian.
[/quote]

Case in point of the manual stays general. :D

So, while you're all looking at that BIG SHINY THING OVER THERE!!!, I'm going to edit my posts to make it clear that the problem all along has been that having a function return false when you're not doing anything with the return value is a script-aborting condition. Everyone's solutions posted here would solve the problem.

[size=1pt]Yeesh, how embarrassing![/size]
 

Veracity

Developer
Staff member
[quote author=Tirian link=topic=345.msg1927#msg1927 date=1155599996]
The problem all along has been that having a function return false when you're not doing anything with the return value is a script-aborting condition.  Everyone's solutions posted here would solve the problem.[/quote]

I'd characterize ASH's state last spring as "immature." This kind of thing - people not being sure how to write scripts that would not get aborted in the middle without the script being able to handle it - was a common complaint. Not to mention the various exceptions & stack traces and other woes.

I took on the task of making ASH rock solid and predictable to the programmer. And one of the ways I did that was to define the following behavior:

Many ASH functions can "fail".

Such operations when performed through the GUI make the sidebar go red and stop execution: trying to eat beyond fullness, adventure when drunk, create something without necessary ingredients, whatever.

Such functions always return a boolean to tell the script whether they succeed or not. If you do not "capture" the boolean result by using it in a conditional, assigning it to a variable, passing it as a function parameter, or returning it as a function value, a failed operation will abort the script. If you DO "capture" the result, the script is saying that it is taking responsibility for deciding how to handle the failure, and the script will not abort.

If the user presses the "cancel" button, the script cannot "capture" that failure; the script will immediately abort.

I went through ASH and very carefully made it allow the script to "capture" the value in every single appropriate context; if the value is being saved for later use, errors do not cause the script to abort.

I'm confident that the core ASH engine works correctly in that way.

Now, there have been any number of cases where a built-in function didn't correctly return false on a failure; it would just return true. Adventuring in the Cyrpt originally returned false after the mini-boss was gone, but later got changed (broken) and returned true, before finally being changed (fixed) to return false again.

Feel free to report bugs if a function whose contract says it returns false on failure (which generally means it aborts the script if you don't "capture" the result) returns true.

Also feel free to report bugs if you "capture" a return value and your script aborts anyway on a failure (other than the user pressing Stop). I'd wager money you won't find any such bugs. :)
 

JBreeze

New member
With version 8.6, the "adventure * defiled nook" command will terminate the script if one you clear it. This is some new code that works with V8.6. It's in ASH, since that's what I prefer to use, but the logic is simple enough to convert to non-ASH if you want.

Code:
if (adventure(my_adventures(), $location[Defiled Nook])){}
else
{
	if (adventure(my_adventures(), $location[Defiled Cranny])){}
	else
	{
		if (adventure(my_adventures(), $location[Defiled Alcove])){}
		else
		{
			if (adventure(my_adventures(), $location[Defiled Niche])){}
			else
			{adventure( 1, $location[Haert of the Cyrpt]);}
		}
	}
}
 
Top