First (real) attempt to make an ash script: Sewer.ash

Theraze

Active member
Yeah... regarding that, I'd probably suggest throwing a my_location() check for the sewers in there...
 

Grotfang

Developer
Yeah... regarding that, I'd probably suggest throwing a my_location() check for the sewers in there...

A perfectly good suggestion if you are looking to do it for anything other than the sewers. I actually prefer returning the page text without the combat check and letting an intelligent script handle specific events. However, as I said, this function was lifted from my hobopolis suite for someone else's hobopolis script.
 

Theraze

Active member
True, true. I just expect someone to search for run_choice at some point in the future and lift it into an unrelated script. :)
 

me259259

Member
Oh man, it's been a very interesting month. But I finally found the time to update this script. It's alllllllllmost done. I added all the features I wanted, and I'm now in the debugging phase. I keep getting this error which I can't figure out. Here's the code:

PHP:
boolean lowerWater = true ;

//boolean wantBurnbarrelBlvd				= false ;
boolean wantExposureEsplanade 			= false ;
//boolean wantTheHeap					= false ;
boolean wantTheAncientHoboBurialGround 	= false ;
boolean wantThePurpleLightDistrict 		= false ;

And I get an error message saying "Script parse error" on the two lines commented out. But the other lines seem to be fine. What's special about those two?
 
There's nothing wrong with the snippet of code you posted, commented or uncommented. Most common cause I've encountered for a script parse error is a missing curly brace.
 

me259259

Member
Try putting a space after the // and see if that helps...

The "//" isn't actually there in the code, I put it there in the example to show which two seemingly arbitrary lines were giving me a problem ;p

There's nothing wrong with the snippet of code you posted, commented or uncommented. Most common cause I've encountered for a script parse error is a missing curly brace.

Hmm... That's very strange then. There aren't any curly braces in that part of the script. The thing that I find really puzzling is that when I comment out wantBurnbarrelBlvd, I get the error on the wantTheHeap line. Why doesn't it have a problem with the line in between those two?

There's one other bug that I discovered after commenting out all the lines that refer to wantLocation variables.

At the end of a repeat... until loop, I have this to stop the loop:

PHP:
string sewers = visit_url ("adventure.php?snarfblat=166") ;

(some lines skipped)

PHP:
until (contains_text( sewers ,"onward and... downward!"))

The error I get says:

Function 'until( boolean )' undefined. This script may require a more recent version of KoLmafia and/or its supporting scripts.

Doesn't contains_text return a boolean?
 
It is very hard to debug anything with so little information. A missing curly brace is the most common mistake I've made that has given a script parsing error, not the only one. Like I said, that snippet of code is fine and throws no errors for me. I don't think the error lies with that part of the code.

Function 'until( boolean )' undefined. This script may require a more recent version of KoLmafia and/or its supporting scripts.

Doesn't contains_text return a boolean?

You are missing a repeat somewhere.
 
Last edited:

Bale

Minion
You need a semi-colon after until()

PHP:
repeat {
 // do stuff
} until (contains_text( sewers ,"onward and... downward!"));

This is on the WIKI.
 

Grotfang

Developer
@me259259:

The information you give is lovely, in that you try to identify the problem yourself and then tell us what you have worked out. However, I recommend posting the entire code up (or at least entire functions) if you want help from others. With your unparsable booleans... nothing is wrong with that code. We would need to be able to check more than those variables to get to the root cause of the problem. In addition, we can't reproduce the problem you are having without a function to return.
 
You need a semi-colon after until()

PHP:
repeat {
 // do stuff
} until (contains_text( sewers ,"onward and... downward!"));
This is on the WIKI.

Leaving off the semi-colon does not give a function undefined error. It gives an "Expected ;, found X" error. Where X is whatever it finds next after the last parentheses.
 
Last edited:

me259259

Member
Ok, I'll post the entire code. Up until now, most of the errors I was getting were basic syntax errors, so I haven't been posting the entire code to not waste people's time. I'm glad to see that I'm finally starting to make intermediate bugs. Woo progress!

The problems are in Sewer.ash, but I included the Glyph Checker just in case.
 

Attachments

  • Sewer.ash
    18 KB · Views: 26
  • Glyph_Checker.ash
    2 KB · Views: 26

slyz

Developer
Here is a your script with some fixes. There is an error left (extraAdventures isn't defined), but I'll let you sort that one.

In most cases, the problem was having only tabs between a variable name and an equal sign. Try using a single space instead next time =)
 

Attachments

  • Sewer.ash
    18 KB · Views: 28

Veracity

Developer
Staff member
I was wondering if it was a tab vs. space issue. Revision 9022 treats tabs like spaces - i.e., ignored whitespace - even when not at start or end of line and not next to another space.
 

me259259

Member
D'oh! I thought I tried changing the tabs to just spaces... This is what I get for debugging after a long day ;p

extraAdventures was a leftover variable from when the script handled adventuring differently. It has been removed from the script.

And now... it works! Hurray! Time to go put this in the turn-burning-scripts section...

Except... hmm... I thought I understood the run_choice thing mentioned earlier... but I was mistaken. Right now it causes looping issues when the script reaches a choice adventure.

Here's the full code that handles adventuring:

PHP:
int poorTeeth = 0;

string sewers = visit_url ("adventure.php?snarfblat=166") ;
repeat 
	{
	// adventure in sewers
	visit_url ("adventure.php?snarfblat=166") ;
	// if it's a combat adventure, obey the custom combat script
	if (contains_text( sewers , "combat"))
		run_combat();
	// handles choice adventures
	string run_choice( string page_text )
		{
			while( contains_text( page_text , "choice.php" ) )
				{
 
				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 );
				// if you gnaw through the C.H.U.M. cage, make a note of it
				if (contains_text( sewers ,"Do you think you're popular enough") && waitForRescue == false && poorteeth < toothTolerance )
					{
					poorteeth +=1 ;
					print ("Ok, you just had to gnaw your way out of the cage.  Let's wait 30 seconds and let someone else be cage bait");
					wait (30);
					}
				if (contains_text( sewers ,"Do you think you're popular enough") && waitForRescue == false && poorteeth == toothTolerance)
					abort ("you already wasted" + toothTolerance * 10 + " turns gnawing out of the cage.  Wait an hour and run this script again, unless you want to waste even more adventures");
				// if the sewer is flooded while the script is running... abort
				if (contains_text( sewers , "terrible ghastly torrent of raw sewage"))
					abort ("Sewers are being reflooded.  Wait until the dungeon is open again");
				// if you tried to turn a valve, and all the grates are opened...
				if (contains_text (page_text, "You tug and tug, but you can't get the crank to budge"))
					grates = 20 ;
				// if you tried to lower the water level, but couldn't...
				if (contains_text (page_text, "but the level of the water doesn't change"))
					water = 20 ;
				if (turnGrates == True && grates <20)
					checkGrates ;
				if (lowerWater == True && water <20)
					checkWater ;
				}
			return page_text;
			
		}
	}
until (contains_text( sewers ,"onward and... downward!")) ;
 
Last edited:

me259259

Member
Hmm... I noticed a few things when I was doing what I thought would be the final, "make sure everything works before I post it" tests. When you use visit_url to adventure, it won't make sure that mafia obeys the mood. It doesn't change your mood, it just doesn't keep up the effects you want in your mood. I could set it up to execute the mood after so many adventures, but then I run the risk of wasting a lot of time, or causing people to not have all of their effects active sometimes. Or I could set it up to have the effects last for 100+ adventures... but that seems extreme. What would you guys recommend?

I might just end up using the adventure command, but I like the visit_url method for two reasons. I want to give support to those who get trapped in the cage, and gnaw their way out, so that they don't end up wasting a ridiculous number of turns in the cage. I also want to make sure that if people want to be helpful and open grates/lower the water levels, that they don't waste turns opening grates/lowering the water level when those things can't be done anymore.

I suppose I could just set it so that you have to wait for rescue... and to check the raid log after every 5 adventures until all the grates/water has been opened/lowered. It'll still waste adventures though, and I'd like to avoid that if possible.
 

StDoodle

Minion
Hmmm... was the "wait for rescue" option removed? Have you tested opening up your preferences file and changing the settings for choiceAdventure211 & choiceAdventure212 to 2? I'm not sure which situation will "waste adventures" and which won't by your viewpoint, though, so I'm not sure exactly what you need.

Also, "mood execute" on the cli does nothing if your mood is currently "filled" adequately, so it shouldn't be a huge waste to call it after every adventure, as far as I can tell.
 

me259259

Member
Well... waiting for rescue will cause the script to stop. I personally would rather wait for rescue than to gnaw through the bars, but that's just me.

I have it set up so that you can specify how many times you are willing to get trapped in the cage. On one of my test runs, I got trapped in the cage 5 times in 10 adventures (not including the adventures wasted gnawing out of the cage). If this is scripted, then you could unwittingly waste a ton of adventures. If you are willing to get trapped only 3 times... I don't know how to get mafia to stop after the 3rd time using ash's adventure command.

By only checking the raid log every 5 adventures to check on the water level and the gates, you'll potentially waste a few adventures by opening grates/lowering the water level, instead of taking the tunnel. Whereas by using visit_location, I can check the raid log every few adventures, and have it read the text from the choice adventure. It it gets the "all grates are opened" message, it will stop trying to open the grates.

Eh, at worst you'll waste 10 adventures, but I would like to avoid that if possible. I could get rid of this feature entirely... but if this script gets used by a lot of people, I would like them to open grates to make the run go by faster for everyone else.
 

StDoodle

Minion
I'm just saying that there should be ways to handle getting trapped, and you'd want to have that choice set to "Wait" in order to actuallyexecute any further steps before it's too late and your adventures are gone. Those steps could easily include a check to see how many times you've been captured, or if there was some other script preference to obey.
 
Top