Calling script /w arguments from another script

What is the ASH methodology for having a script call another script that takes an argument?

Right now, I'm getting around the problem by doing this:
Code:
cli_execute("call foo 3");

But when I try:
Code:
call "scripts\foo 3";
or
Code:
call "foo 3";

I get the following error: "Variable reference expected for function name."

I'm also curious how you'd handle the main() of the called script returning a value that the original script must parse. That's something that you can't do with cli_execute, it seems.
 

matt.chugg

Moderator
in ash you "import"

for example, zarqon has a script in which he keeps many functions that he uses in all his scripts, at the top you just import the script

Code:
import <zlib.ash>

now all the functions in zlib.ash are available in whatever script imported it!

hmm, I could probably explain that more eloquently (and probably spell eloquently right too)
 
A related question: if I write something like the VIP pool script without a main() function, is there any way for me to call it from the graphical CLI or do I then need a wrapper script that does have a main()?

For instance, I'd like to be able to call play_pool() from an aftercore farming script, but I'd also like to be able to call play_pool() from the CLI when I want to trigger some of the buffs during hardcore without going to the browser.

Is there an easy way to "import" my new function so that the graphical CLI knows about it, or is writing a wrapper that calls it the only way to accomplish that?
 

Alhifar

Member
Just include a main() function in the script that passes along the correct arguments to the other function. main() is never imported.
 

matt.chugg

Moderator
from the wiki

using <filename>
(using new_commands.ash)

Allows all ASH functions defined in the given file to be used as though they were CLI commands in both the gCLI and the standard CLI (in programmer terms, the ASH functions are imported into the CLI namespace). The given file will remain in the namespace, even after subsequent "using" commands are issued for different files, and will remain in the namespace until KoLmafia's data files are cleared or the "commandLineNamespace" property is modified.

slightly ninja'd but i'm claiming victory for a more accurate answer! :p ;)
 

Alhifar

Member
I've found "using" to be a bit... strange. You have to be careful not to typo or to move the file, or things get all screwed up.
 
Just include a main() function in the script that passes along the correct arguments to the other function. main() is never imported.

I tried that, but when I include a main() function, then importing that ASH into another one gives me this error:

"main method must appear at top level"
 

Alhifar

Member
It works fine for me, for a quick test I used the following:

test.ash
Code:
import <test2.ash>;
void main()
{
	test();
	print( "tested!" );
}

test2.ash
Code:
void test()
{
	print( "testing!" );
}
void main()
{
	test();
}

Output:
Code:
> test

testing!
tested!

> test2

testing!
 
Ah, I see what happened.

I had my import <> inside my main() function instead of declared above it. So it was actually trying to import a main() into another main(). Doh!

Thanks for the help.
 
Top