Handling choices

Veracity

Developer
Staff member
I added a couple of functions in revision 17937 to make it a little easier for scripts to handle choice adventures:

Code:
Visiting a Science Tent
Encounter: Dr. Gordon Stuart, a Scientist

[color=green]> ash last_choice()[/color]

Returned: 1201

[color=green]> ash available_choice_options()[/color]

Returned: aggregate string [int]
1 => Great!

[color=green]> choice 1[/color]
Not all choices are always available. If you were expecting choice 2 to exist, doing run_choice( 2 ) will not work; you will remain in the choice.

I suspect that most code will not care about this and those that do can come up with the same data by parsing the page returned by visit_url, but these functions call internal KoLmafia methods which already do all of that.
 

ckb

Minion
Staff member
This looks super-duper useful!

Any chance we can add the Mafia (relay) spoiler text to the choice lists too?
 

Veracity

Developer
Staff member
I could. There is an internal function which returns a map - just like that one - but with " (SPOILER)" added to KoL's text.

I'll make two-argument version of available_choice_options where the 2nd argument is a boolean saying whether to include the spoiler. The one argument version will default to false. Let the script decide if it wants the spoilers or not.

By the way - I was interested in this because I have one character who gets this:

Code:
[color=green]Visiting a Science Tent[/color]

[color=green]> ash last_choice()[/color]

Returned: 0

[color=green]> ash available_choice_options()[/color]

Returned: aggregate string [int]

[color=green]> choice 1[/color]

[color=red]You aren't in a choice adventure.[/color]
According to the DEBUG log, I am on choice.php - but there is no choice form.

Dr. Stuart says "Great! Head over to Seaside Town and see this through to the end!"

Perhaps I never actually went to Seaside Town in the Relay Browser with this character, although I did do everything else in the event?

(Checking)

That is exactly right. Now I get the expected choice options.

Code:
[color=green]> ash available_choice_options()[/color]

Returned: aggregate string [int]
1 => Can I fight that tentacle you saved for science?
2 => Great!
Or even:

Code:
[color=green]> ash available_choice_options()[/color]

Returned: aggregate string [int]
1 => What can you tell me about this Eldritch Essence stuff?
2 => Can I fight that tentacle you saved for science?
3 => Great!
Which is why I needed this; the option for fighting the tentacle may vary or be unavailable.
 
Top