Need help with my script

silveran

New member
Hi i'm a noob at scripting but i've so far managed to cannibalize a couple scripts out there to suit my needs. But there's something wrong with the castle farming script I'm working on right now.

My aim is to send the pulverisable castle drops to smash/wadbot, followed by ending my session with ode to booze from a buffbot & overdrinking. The script is meant to wait till i have acquired ode to booze before drinking.

But all i get is my script endlessly waiting.

Any help would be appreciated!

View attachment Castle_Farm.ash
 
Last edited:

Winterbay

Active member
First: You have two main-functions. That won't really work out IIRC.
Second: Code after main() won't ever get run. Also, IIRC :)

Deleting the first main and turning the second into
Code:
void main()
{
	smash_today();
	ode_booze();
	if(have_effect($effect[Ode to Booze]) < 1)
		repeat {
			wait(5); refresh_status();
		} until (have_effect($effect[Ode to Booze]) > 1);
}
should work, I think.
 
There's no problem with putting code after main. The problem is the loop that waits for ode is top-level code, meaning it is not inside of any of your functions, top-level code is always executed first, even before main(), then the code in main() is executed. There is no reason for two main functions. Like Winterbay demonstrated you can call as many other functions as needed from within one main.

It appears that Mafia doesn't throw an error if you have two main() functions declared. It looks like the first one is overwritten with the contents of the last function declared main.
 

silveran

New member
@Winterbay VERY VERY NICE. That totally did the trick! Any way i could repay your help? Dont mind sending some meat your way ^^

Thanks again! :D

@FN Ninja Thanks for explaining! :)
 

Veracity

Developer
Staff member
ASH parses and verifies the whole script.
Top-level commands go in their own executable section, apart from functions.
It bails when it sees the first error.
If there is no error, it executes the script.
First it executes all top-level commands - often to initialize global data, but any arbitrary top-level code is fine.
Then, if there is a main() function, it calls it.
(If there is no main() function, no problem. You don't need one; top level code works perfectly well.)

Edit: or, to put it more technically:

Every Scope can include types, variables, functions, and code that are available within that scope and any lexically enclosed Scopes.
The ASH script file defines a Global Scope. types, variables, functions, and code defined there are in the Global Scope and are available within that file and within all lexically nested scopes.
main() is just a function defined in the Global Scope.

When the file is loaded and verified, ASH first executes all the commands defined in the Global Scope and then executes main(), if any, from the Global Scope.
 
Last edited:
Top