choice adventures complement of run_combat?

Paragon

Member
Is there a method to do something along the lines of run_choice();
currently I have a script that works fine until it comes across a choice adventure, even when i have the choice adventure defined and a choice selected the script gets caught up in the choice adventure and can't continue. I have a work around which involves cli_execute("refresh all"); which will obviously refresh all my information but it also completes the choice adventure for me in the process... I was hoping that there might be a more elegent solution.
 

zarqon

Well-known member
A crazy idea that might work, but would involve a lot of string parsing:

If there were some way of getting the number of the choiceadv from parsing the page (I'm thinking it would be in the action property of the form tag), you could probably use that to check the corresponding choiceAdventureXX property, then use visit_url to complete the proper choice. That last step would be the hardest.

This has been a recurring issue for a lot of coders. Perhaps it's time to request an ASH run_choice() function.
 

Alhifar

Member
I'm out of adventures, so I can't test it yet, but the following should work. It will return the page text of the completed choice adventure. It probably doesn't work right with multi stage choice adventures, though passing the resulting text through again should complete the next part too.

Code:
buffer run_choice( buffer page_text )
{
	## Get choice adventure number
	int begin_choice_adv_num = index_of( page_text , "whichchoice" ) + 18;
	int end_choice_adv_num = index_of( page_text , "><input" , begin_choice_adv_num );
	string choice_adv_num = substring( page_text , begin_choice_adv_num , end_choice_adv_num );
	
	string choice_adv_prop = "choiceAdventure" + choice_adv_num;
	string choice_num = get_property( choice_adv_prop );
	
	string url = "choice.php?pwd&whichchoice=" + choice_adv_num + "&option=" + choice_num;
	page_text = visit_url( url );
	
	return page_text;
}
 

Alhifar

Member
Code:
buffer run_choice( buffer page_text )
{
	while( contains_text( page_text , "choice.php" ) )
	{
		## Get choice adventure number
		int begin_choice_adv_num = ( index_of( page_text , "whichchoice value=" ) + 18 );
		int end_choice_adv_num = index_of( page_text , "><input" , begin_choice_adv_num );
		string choice_adv_num = substring( page_text , begin_choice_adv_num , end_choice_adv_num );
		
		string choice_adv_prop = "choiceAdventure" + choice_adv_num;
		string choice_num = get_property( choice_adv_prop );
		
		if( choice_num == "" ) abort( "Unsupported Choice Adventure!" );
		
		string url = "choice.php?pwd&whichchoice=" + choice_adv_num + "&option=" + choice_num;
		page_text = visit_url( url );
	}
	return page_text;
}

That should take care of unsupported choice adventures, if I'm not mistaken.

EDIT: Found a multi with some turns, and did a few tests. Found a small bug, but it should be working just fine now.

EDIT2: Should work with multi-step choice adventures now. I think.

EDIT3: That'll teach me to code at 6:00 AM.
 
Last edited:

dj_d

Member
Much thanks for this! Here's a small variation that should handle both choiceadvs and regularadvs (so you can just throw anything at it).

Code:
string run_adv( string page_text )
{
 if( contains_text( page_text , "choice.php" ) )
 {
  while( contains_text( page_text , "choice.php" ) )
  {
   // Get choice adventure number
   int begin_choice_adv_num = (index_of(page_text, "whichchoice value=") + 18);
   int end_choice_adv_num = index_of(page_text,"><input",begin_choice_adv_num);
   string choice_adv_num = substring(page_text,begin_choice_adv_num,
					end_choice_adv_num );
   
   string choice_adv_prop = "choiceAdventure" + choice_adv_num;
   string choice_num = get_property( choice_adv_prop );
   
   if( choice_num == "" ) abort( "Unsupported Choice Adventure!" );
   
   string url = "choice.php?pwd&whichchoice=" + choice_adv_num + "&option=" + choice_num;
   page_text = visit_url( url );
  }
 }
 else
 {
  print("running combat");
  page_text = run_combat();
 }
 return page_text;
}
 
Top