Results 1 to 2 of 2

Thread: multiple main functions in a script

  1. #1
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    12,248

    Default multiple main functions in a script

    I was looking into an issue with VMF. That script will collect semirares for you (if configured to do so). It will also bust ghosts and fight vote monsters. All of those are on their own schedules, so when consuming adventures, it will break out to perform the designated actions and then continue. Which is to say, it essentially has a counter script built in.

    However, the script will also call other scripts to consume turns (if configured). In particular, Gingerbread City and Spacegate. Since neither of those will collect semirares, if your counter expires while running them, they proceed and you lose it.

    I'm considering making a custom counterScript, integrated with VMF, which will be active while running external scripts. Looking at how KoLmafia invokes a counterScript:

    Code:
    			KoLmafiaASH.logScriptExecution( "Starting counter script: ", scriptFile.getName(), interpreter );
    			Value v = interpreter.execute( "main", new String[]
    			{
    				expired.getLabel(),
    				String.valueOf( expired.getTurnsRemaining() )
    			} );
    			KoLmafiaASH.logScriptExecution( "Finished counter script: ", scriptFile.getName(), interpreter );
    The property "counterScript" contains the name of an ASH file.
    When a counter expires, that script is invoked via

    boolean main( string name, int remaining );

    In the context of my scripts, which only go places that take a single adventure at a time, remaining will always be 0, and the semirare (whatever) will occur on the very next adventure.

    VMF contains a function:

    void main()

    This is the method which is invoked if you simply execute the script. I wonder if I could overload it and have

    boolean main( string name, int remaining )

    and simply set VMF as its own counterScript while it is executing, and thereby having access to all its own internal state? Intriguing!
    Ph'nglui mglw'nafh Cthulhu
    R'lyeh wgah-nagl fhtagn.

  2. #2
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    12,248

    Default

    Actually, since we synchronize on the interpreter used to execute a particular script, even if I can overload the main function like that, the counterscript would be blocked when the main script was running. Thus, no updating shared data. I could still do semirares with a custom counterScript, but I'd have to update my internal variables (and drink another Lucky Lindy) after calling the external script.

    Sigh.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •