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

Fluxxdog

Active member
Heh, no I mean I'm getting that code during my run as I hunt down White Citadel, no manipulation. It's one of those "I have testicles!" ordeals. Or maybe more like "I once caught a fish this big!"? Yeah, we'll go with the fish story.
 

me259259

Member
You can use the lastEncounter mafia property. It updates as soon as you get a new encounter, not once the adventure is over.

Hmm... I was thinking about making the script adventure for an additional 10 adventures should you decide to gnaw out of the cage. Would something like this work?

PHP:
adventure(100 , $location[a maze of sewer tunnels] );

// If you get trapped in the cage, and you decide to gnaw your way out
// adventure in the sewers for 10 adventures every time you get trapped in the cage
int extraAdventures = 0
if (get_property("lastEncounter") == Despite All Your Rage)
	extraAdventures += 10 ;
	
adventure(extraAdventures , $location[a maze of sewer tunnels] );

And Bale, thank you! And now I get to learn how to import scripts into this one...
 

slyz

Developer
This won't work, since once your are done running 100 adventures lastEncounter could be anything. Try like this:
PHP:
int advs_to_spend = 100;
while( advs_to_spend > 0 )
{
    adventure(1 , $location[a maze of sewer tunnels] ); 

    // If you get trapped in the cage, and you decide to gnaw your way out 
    // adventure in the sewers for 10 adventures every time you get trapped in the cage 
    if (get_property("lastEncounter") == "Despite All Your Rage") 
        advs_to_spend  += 10 ;
    else advs_to_spend  -= 1 ;
}

You would have to test it to be sure Mafia stores the name as "Despite All Your Rage", and make sure to put quotes around the name. If getting caged takes an adventure, you might want to increment advs_to_spend by 11 instead of 10.
 

me259259

Member
The KoLMafia wiki is always a good place to start learning about such things: import

Indeed. I've been doing my best to only ask people how to do things if I couldn't find the answer on the wiki first. What I said about getting to learn how to import scripts, I didn't mean to say it with sarcasm or anything. I'm a practical person. It's hard for me to learn theory unless I can use the theory and practice using it in the near future. I'm glad that I have an excuse to need to learn how to import scripts, because otherwise it could be a long time before I try to learn it. And I have a feeling it's going to be one of those things that the sooner I learn how to use it, the better.

I'm not a computer programmer, and I've only recently begun to fiddle around making my own scripts and programs. Ash is my first language because everything I learn about it I can use almost immediately. And heck, since I started this project, I've learned so much about the basics of programming languages, it's wonderful. It's why, even though the sewer.ash I uploaded onto the forums fits my needs, I continue to work on sewer.ash. Thinking about what I want it to do, translating from English to Ash, trying to plan for other people's needs, finding the best ways to do things... its been a lot of fun these past couple of days! The more excuses to learn, the better I say!

And slyz, I don't know if I'll be able to actually tests if mafia stores the last encounter as "Despite All Your Rage" if you get that adventure. I'm part of a clan that has a dedicated cagebot. And I'm an old fashioned 1 account kind of person. Does anyone have a clan I can temporarily join that will let me test this?
 

Winterbay

Active member
If you want to poke around in our basement you are free to do so. We almost never have a cagesitter (we are too few to do that meaningfully) so the cage is often free to test in :)
IGN: Winterbay
 

me259259

Member
Hey everyone, sorry for disappearing for a couple of weeks. It's been a crazy Crimbo.

Winterbay, thank you! I'll take you up on that hopefully tomorrow!

I'm almost ready to release the version I've been working on. I've run into a problem I don't quite understand. Here's what I have:

PHP:
if  (hoboGlyphs >= 17 && hoboGlyphs <=20 )
	int amount = 10 ;

And I get this error: "unknown variable int". The thing that I don't understand is that if I do something like this:

PHP:
if (hoboGlyphs >= 17 && hoboGlyphs <= 20)
	print ("It works!");

It works. I'm thoroughly confused. Has mafia grown sentient, and is punishing me for my long debugging sessions?
 

Theraze

Active member
If used in a more complicated way, defining and setting values in the same step sometimes has issues. You should be fine if you do the following:
PHP:
int amount;
if  (hoboGlyphs >= 17 && hoboGlyphs <=20) 
    amount = 10;
 

me259259

Member
Thank you Theraze! That fixed it. Huh, I wonder why that slight complication would mess it up...

Anyway, here's my new version of sewer.ash.

Changelog: 1/4/11

There are a large number of user preferences at the top of the script. Be sure to look at them before you run the script!

You can now set your outfit, mood, familiar, and custom combat script that you'll use in the sewers
You can also set your outfit, mood, familiar, and custom combat script for when you leave the sewers

The script now checks to see if you have a hobo code binder equipped. If you have a binder, but don’t have it equipped, the script will abort. Set checkBinder to false if you want to adventure without a binder.

It has a similar function for gatorskin umbrellas. To disable, set checkUmbrella to false.

The script will let you decide if you want to do should you get trapped in the C.H.U.M.s’ cage. Gnaw through the bars (at the cost of 10 adventures) or wait for rescue. Waiting will abort the script. Default is to gnaw through the bars.

The script now gives you an option on what to do with the base materials you get during the run. Whether you want to convert them to the items you need to make the run faster, mallsell them, send them to sellbot, or just ignore them.

The script now checks how many hobo glyphs you have in your binder. And when I say "checks", I mean it runs Glyph_Checker.ash that will check how many glyphs you have. To stop the script from checking for glyphs before every run, set checkGlyphs to false. You should check for glyphs at least once before running Sewer.ash. If you don't check for glyphs, it assumes that you have no glyphs, and will compensate by buying a ton of items needed for the tunnels. If you know how many hobo glyphs you have, if you type "set hoboGlyphs = X" in the cli, Sewer.ash will assume you have X hobo glyphs, and buys items accordingly.

The script now notifies me if you’re using it.

Planned updates:

Will do some testing to see if the script will adventure for an additional 10 adventures if you have to gnaw through the cage.

Will set it to check the logs to see if all grates/valves have been opened/turned. If the are nouns to be verbed, it will not take the tunnel, and will instead verb the nouns. Will make it so you could just always take the tunnel if you don’t want to be helpful.

Will make a thread in the "Turn Burning Scripts" section later tonight for this script... because I probably should.
 

Attachments

  • Sewer.ash
    10.9 KB · Views: 22
  • Glyph_Checker.ash
    2 KB · Views: 21
Last edited:

Bale

Minion
Huh, I wonder why that slight complication would mess it up...

It was strange, but I suspect it would have worked if you had put {} around it. (If so, that would count as a bug in ash.) Anyway, I would never have tried that for an entirely different reason: That would have caused a different bug later.

If you declare a variable inside an if statement (while, foreach, or any other control structure) that variable will not be defined outside the control structure. So, if you had tried to access the value of amount in a later section of code it would have told you that amount is an undefined variable. Just as functions contain local variables, all other control structures do the same.

dl/dr; Never declare a variable inside a set of curly brackets {} unless it is used ONLY inside that set of curly brackets.
 
Last edited:

Veracity

Developer
Staff member
It was strange, but I suspect it would have worked if you had put {} around it. (If so, that would count as a bug in ash.)
Or, maybe it wouldn't "count as a bug in ash". :)

An "if" or "else" or "while" or such takes a "statement" as its body. A "block" - an ordered sequence of declarations and/or statements surrounded by {} - also counts as a "statement". A variable declaration - like "int amount = 10" - is NOT a statement.

Now, it so happens that that particular declaration also includes an initialization, which is, essential, an assignment statement. But, as you pointed out, it's completely useless to have that be the only thing happening in the body of an if, since the variable will not be visible outside of the body. If the value you are assigning is the result of a function call with side effects - "int amount = some_function(10)", where some_function not only returns an integer but also sets some global variable or something - then that declaration WILL have effects outside of the body - but you may as well simply call "some_function(10)" - which IS a statement - rather than futilely assigning it to a local variable.

I don't consider "a variable declaration is not a statement" to be a bug, but even if I did, I wouldn't waste my time fixing it, since it is completely useless for ASH coders to think of it like that.
 

heeheehee

Developer
Staff member
Yeah, as Veracity and Bale stated, amount wouldn't be available outside of the scope of the if statement, either way.

Also, why bother with the second part of the conditional? It's impossible to get more than 20 hobo glyphs, so you might as well say "if (hoboGlyphs > 16)".
 

me259259

Member
Also, why bother with the second part of the conditional? It's impossible to get more than 20 hobo glyphs, so you might as well say "if (hoboGlyphs > 16)".

In case of human error. You can manually set how many hobo glyphs you have if you never want to run the glyph checker. What if someone accidentally sets hoboGlyphs = 23 instead of 12? I felt it would be a common enough error to just left the script automatically alert the user to what the problem was. If I did things right, I set up a similar thing in case people actually set hoboGlyphs = X.

As for variables in if statements... Ah. Ok, that makes sense. I thought a local variables were specific to large functions (like main, or a called subroutine... man I hope I'm using these words correctly), and that controlled structures and data structures were too small to have their own local variables. I did happen to try {} brackets to try and solve the problem, but then I would get an error later on saying something like "variable amount not found". That explains quite a bit.
 

Bale

Minion
I don't consider "a variable declaration is not a statement" to be a bug, but even if I did, I wouldn't waste my time fixing it, since it is completely useless for ASH coders to think of it like that.

I withdraw my cry of bug, please forgive me. :)

It's a pretty harmless problem anyway, since it will only appear if the programmer has committed a scope error.

I did happen to try {} brackets to try and solve the problem, but then I would get an error later on saying something like "variable amount not found". That explains quite a bit.

That's the real problem I went to lengths to explain. I'm glad I helped.
 

Grotfang

Developer
I'm curious. Line 97:

Code:
int to_int (string hoboGlyphs);

What does this do?

To demonstrate, type this into the CLI:

Code:
ash string x = "12"; if( x > 10 ) print( "Done" );

I believe your code will work perfectly well without that line.
 
Top