Creating/calling an importable script

muffins

Member
Hello!

I am waaaay rusty in any remote programming knowledge I once had, so, I need some help...

I run my char using the Schduled Tasks in Win2k Pro nightly to basically farm whatever items I might need before the next ascension. I *could* make some uber-complicated script that checks the amount of certain items, if the char doesn't have them, it advs in one area, then on to the next item and so on and so forth, but... well, I'll get to that later.

Right now, I'm just looking for a way to simplify things.

I hate having to reenter my pass every time I make changes to a scheduled task, but I occasionally like to switch up the location. Right now, I have three separate scripts and just change the file name in the task each time I want to go somewhere else.

What I'd *like* to do is go ahead and create three separate files that specify what's to be done in each location, but call them in a fourth file that just contains, essentially, an import for the location, a login, a call to start the adventuring, and an exit command.

I've got the adventuring scripts all written out and working, but I have no idea what to change to make them "callable" from the main script. Can someone help me out, please?

Sorry that was a bit rambling, and thanks in advance!
 

Nightmist

Member
[quote author=macman104 link=topic=86.msg276#msg276 date=1145181477]
Code:
import <filename.ash>;
[/quote]

the "<>" are intentional, the first time I did that I assumed they were just like the "[]" used in functions, I assumed wrong. XD
 

muffins

Member
Oh... is that all that needs to be done?

Well... I would need to rename void main() to void whatever() in order for them to successfully run, right? Considering void main() would be at the beggining of the main file that would be importing them, I would think that would cause some sort of confusion... or do I leave that part out altogether in the adventuring files and just start them at

Code:
while( my_adventures() > 0 )
{
adventure( 1, $location[*Location*]);
...etc.

?
 

macman104

Member
yes your other imports, I don't think should have a main in them. Also, have any imports, and other functions you are using defined, BEFORE you have main. Main should be the last function in your program.
 

muffins

Member
So, would it be

Code:
void main()
{
cli_execute("login charname");
import <filename.ash>;
cli_execute("exit");
}

with filename.ash only containing, just for example

Code:
while( my_adventures() > 0 )
{
adventure( 1, $location[*Location*]);
while ( have_effect( $effect[Beaten Up]) > 0)
{
cli_execute("uneffect Beaten Up");
cli_execute("galaktik HP");
}
}
cli_execute("stash put * item1");

? Or would the filename.ash file need to contain an opening void whatever() statement that would be called in some way from the main file?

Also, I don't think I've had a situation where it needed to be tested yet, but does the Beaten Up "repair process" code look right?
 

macman104

Member
Actually you'll put all of your imports at the very top of your program. So it'd look like this, let's say just for the example, that I also have func1 and func2.
Code:
import <filename.ash>;
void func1()
{
  funciton stuff...;
}

void func2()
{
  function stuff...;
}

main()
{
  cli_execute("login charname");
  func1();
  func2();
  healing();
  cli_execute("exit");
}

Oh, also yes, you need to have some sort of function in your import. You can't just call the file, all the import does is give you access to the functions in that file. So in the above example, I'll add the filename.ash contains the function, healing(). Yes, you beaten up code looks right as long as you have soft green echo eye drops with you. I'm not sure if mafia utilizes other resources besides those. So you need to make sure you have those on hand.
 

muffins

Member
I'm not sure if I did something wrong here, but I'm getting an error:

File castle.ash not found at line 1 in file C:\KOLmafia\CLIscripts\charname.ash
net.sourceforge.kolmafia.KoLmafiaASH$AdvancedScriptException: File castle.ash not found at line 1 in file C:\KOLmafia\CLIscripts\charname.ash

castle.ash contains:
Code:
void castleintheclouds()
{
while( my_adventures() > 0 )
{
adventure( 1, $location[Castle in the Clouds in the Sky]);
cli_execute("status refresh");
while ( have_effect( $effect[Beaten Up]) > 0)
{
cli_execute("uneffect Beaten Up");
cli_execute("galaktik HP");
}
}
cli_execute("stash * Angry Farmer candy");
cli_execute("stash * awful poetry journal");
cli_execute("stash * chaos butterfly");
cli_execute("stash * disturbing fanfic");
cli_execute("stash * furry fur");
cli_execute("stash * giant needle");
cli_execute("stash * Heavy D");
cli_execute("stash * Mick's IcyVapoHotness Rub");
cli_execute("stash * Original G");
cli_execute("stash * plot hole");
cli_execute("stash * probability potion");
cli_execute("stash * procrastination potion");
cli_execute("stash * Thin Black Candle");
cli_execute("use * Warm Subject gift certificate");
cli_execute("stash * wolf mask");
cli_execute("galaktik HP");
}

and the charname.ash contains:
Code:
import <castle.ash>;
void main()
{
cli_execute("login *charname*");
castleintheclouds();
cli_execute("exit");
}

It looks right from what you've given me, but it's saying it can't find the file, even though it's in the same directory as the script that's calling it. :(
 

Nightmist

Member
[quote author=muffins link=topic=86.msg283#msg283 date=1145189623]
It looks right from what you've given me, but it's saying it can't find the file, even though it's in the same directory as the script that's calling it. :(
[/quote]

The import thing always bases itself from the scripts directory. (So try sticking castle.ash straight into the scripts directory)
 

muffins

Member
Oh, that... kinda/sorta stinks, heh...

Actually, I just moved the castle.ash file to the scripts folder, and it's still giving that error... does the charname.ash file have to be in there, too? 'Cause I'd rather it weren't... I've got enough scripts in there as it is. :-\

Edit: Actually... I just tested that, too, and it's still reporting file not found!

Edit #2: Okay... this is one little quirk with running KOLmafia from a scheduled task, but... I had to copy the script into C:\Program Files\Java\jre1.5.0_06\bin\scripts\ because that's apparently where something (kolmafia, java, windows, who knows?) thinks it's calling KOLmafia from when it's riunning as a task...

Who would I make a change request to on letting the import script feature work from the current directory the script is in (i.e. is that a part of mafia)? This would save me a lot of time and trouble from having to remember to change a script in up to three different places any time I want to make a change...

...or...

Edit #34590809: I'm not too fond of using Scheduled Tasks, I generally stop trying to make them better once they work in any sort of form... however, I know now why it's trying to create the data/script directories in there and want to change it...

Right now, the task is "C:\Program Files\Java\jre1.5.0_06\bin\java.exe" -jar C:\KoLmafia\KoLmafia.jar --CLI script=C:\KOLmafia\CLIscripts\charname.ash which works all well and good, but I'd like to have something more along the lines of "C:\WINDOWS\system32\cmd.exe" java -jar C:\KoLmafia\KoLmafia.jar --CLI script=C:\KOLmafia\CLIscripts\charname.ash with it starting in directory C:\KoLmafia\ ... of course, this isn't working, it'll just bring up a window with C:\KoLmafia\ and sit there, does anyone know of a way of making this happen?

Thanks in advance, and thanks for all previous help! :)
 

Nightmist

Member
[quote author=muffins link=topic=86.msg285#msg285 date=1145191671]
*Confusing 0_o*
[/quote]

Uh im not too sure what your trying to say but I personally use the Scheduled Tasks to start a batch file rather then KoLmafia directly (Although personally I dont see how that would affect it)
Code:
@echo off
title *Some sort of title*
cd *Something like D:\KoL\7.1*
echo *Some sort of descriptive message about what its doing//going to do*
pause
java -jar D:\KoL\7.1\KoLmafia-7.1.jar --CLI script=*Script Location*

Yes, I like to have a little pause just incase I dont want to run it (Such as a KoL holiday and theres other things to do.)

I dont see how this really helps but I import and use the Scheduled Tasks without any problems with the above.
 

muffins

Member
Heh, actually, that helped muchly.

Sorry for the confusion, it was late, err, early... and I hadn't slept.

Thank you so much for all your help!
 
In my scripts directory is a subdirectory called subscripts My script importing a subscript (an ash in the subscripts folder) would contain:
Code:
import <\subscripts\scriptname.ash>;
My scripts directory is very messy too :p
 
Top