Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 11 to 20 of 22

Thread: Discussion: Standards in relay over-ride scripts

  1. #11
    Member
    Join Date
    Apr 2007
    Location
    Russia
    Posts
    63

    Default Re: Discussion: Standards in relay over-ride scripts

    When talking about "several scripts on one page", don't forget about visit_url() function.

    If I understand correctly, KoLmafia calls relay script before executing request to KoL server. This is what visit_url() does. However, URL parameters still accessible to script.

    Look at "disco combos" or "El Vibrato" scripts (yes, I'm talking about fight.php overrides again). It adds form with non-standard actions which is checked before executing visit_url() and may generate some more requests (and it's results are returned instead of visit_url()). What would happen if this request will be passed to game server? We have two-and-a-half "parts" here:

    1. check, if we must do Something Different before posting request to server
    1.5. do Something Different and return result as page buffer OR execute visit_url()
    2. do it's main job with page buffer passed as argument and return modified page buffer

    So, KoLmafia should call each script at least two times:

    boolean check_pre() - for each script to see if it wishes to do some additional actions
    buffer do_pre() - if any script returns true in check_pre() (first non-false script) OR visit_url() if all scripts return false
    buffer main(buffer) - for each script, passing modified page to next script

    "First non-false script" means that any two scripts can't trigger additional actions at the same time on same conditions. Script writes should take care of it.
    My KoLmafia script repository: gitweb, snapshot in tar.gz archive

  2. #12
    Senior Member
    Join Date
    Mar 2006
    Posts
    729

    Default Re: Discussion: Standards in relay over-ride scripts

    Hmm, what would happen if the script I wrote for the degrassi knoll general store were to have the additional items it adds to the store passed to the server? Nothing interesting, but that concept does add a new list of problems. This takes us right back where I was in the first post. The difference would be in the wrapper script.

    [quote author=raorn link=topic=1538.msg7529#msg7529 date=1205075182]
    So, KoLmafia should call each script at least two times:

    boolean check_pre() - for each script to see if it wishes to do some additional actions
    buffer do_pre() - if any script returns true in check_pre() (first non-false script) OR visit_url() if all scripts return false
    buffer main(buffer) - for each script, passing modified page to next script
    [/quote]

    I disagree with that concept. I actually think that trying to work with that model would lead to more trouble than it is worth when we could easily make a shell script based on the needs of the merging of the 2 scripts.

    When you look at it from that perspective, it does become more counterintuitive. When you narrow your perspective to just adding a few easier to get to links, it is less so.

    This leaves me with the thought that a cli or menu command to add or remove scripts from the pool, and a single file to load at startup which tells Kolmafia whats what would be the best plan. New question: with the concept of adding and removing scripts via the file at startup, and other commands while running would it be more feasible to keep the script constantly in memory unless the script is removed? That idea would seemingly also cut back on the performance loss of relay scripting.

  3. #13
    Member
    Join Date
    Apr 2007
    Location
    Russia
    Posts
    63

    Default Re: Discussion: Standards in relay over-ride scripts

    [quote author=efilnikufecin link=topic=1538.msg7531#msg7531 date=1205081394]
    I disagree with that concept. I actually think that trying to work with that model would lead to more trouble than it is worth when we could easily make a shell script based on the needs of the merging of the 2 scripts.[/quote]
    In this case only autoloading of "wrapper" scripts makes sense.

    New question: with the concept of adding and removing scripts via the file at startup, and other commands while running would it be more feasible to keep the script constantly in memory unless the script is removed?
    Can you check mtime of a script and reload it if it's changed?
    My KoLmafia script repository: gitweb, snapshot in tar.gz archive

  4. #14
    Developer
    Join Date
    Mar 2006
    Posts
    1,367

    Default Re: Discussion: Standards in relay over-ride scripts

    All parsed ASH scripts are kept in memory.

  5. #15
    Senior Member
    Join Date
    Mar 2006
    Posts
    729

    Default Re: Discussion: Standards in relay over-ride scripts

    [quote author=raorn link=topic=1538.msg7543#msg7543 date=1205145980]
    Can you check mtime of a script and reload it if it's changed?
    [/quote]

    I believe that is how it is, that it is checked.

    [quote author=holatuwol link=topic=1538.msg7551#msg7551 date=1205173658]
    All parsed ASH scripts are kept in memory.
    [/quote]

    I should have been more clear, if Kolmafia does check to see if the script has been modified, then eliminating that step might be an option that could increase the performance of relay over-ride scripts. While debugging a script in progress, when modified the user could just re-execute the method to add the script to the pool. I don't know if this would be enough of a gain to constitute the effort though.

    OT (sort-of) if Kolmafia checks the modified date of the script to determine if it should be re-loaded, then instead of locking the file, could Kolmafia instead open the file share-aware? Kolmafia technically is share aware (if that is the case), and it would mean that when an exception occurs during parsing of a script, the file would not be locked, and the user/writer would not be forced to shutdown and restart Kolmafia. Normally when I encounter an error in a script I am writing, it is a parse error like having 6 opening ( and only 5 closing ).

  6. #16
    Member
    Join Date
    Apr 2007
    Location
    Russia
    Posts
    63

    Default Re: Discussion: Standards in relay over-ride scripts

    [quote author=raorn link=topic=1538.msg7529#msg7529 date=1205075182]
    So, KoLmafia should call each script at least two times:

    boolean check_pre() - for each script to see if it wishes to do some additional actions
    buffer do_pre() - if any script returns true in check_pre() (first non-false script) OR visit_url() if all scripts return false
    buffer main(buffer) - for each script, passing modified page to next script
    [/quote]

    ASH implementation. Main disadvantage is that I need to edit script to add something and check for namespace intersections. Things could be much easier if KoLmafia can do this job automatically.

    Code:
    import </relay/fight_buttons.ash>;
    import </relay/fight_info.ash>;
    //import </relay/fight_XXX.ash>;
    
    void main()
    {
    	buffer page;
    
    	if (buttons_check()) {
    		page = buttons_preaction();
    	} else if (info_check()) {
    		page = info_preaction();
    	//} else if (XXX_check()) {
    	//	page = XXX_preaction();
    	} else {
    		page = visit_url();
    	}
    
    	page = buttons_main(page);
    	page = info_main(page);
    	//page = XXX_main(page);
    
    	page.to_string().write();
    }
    
    // vim: set ft=javascript ts=4:
    P.S. Posting this here for archiving purposes.[hr][quote author=efilnikufecin link=topic=1538.msg7531#msg7531 date=1205081394]I disagree with that concept. I actually think that trying to work with that model would lead to more trouble than it is worth when we could easily make a shell script based on the needs of the merging of the 2 scripts.[/quote]

    What do you think about these functions:

    void import(string) - acts as import <>;
    value call(string, ...) - calls function by name passed as string argument.

    So I could write something like this:

    Code:
    string modules = get_property("somepageRelayModules").split_string("\\s*,\\s*");
    
    foreach m in modules
      import("/relay/somepage_" + m + ".ash");
    
    void main()
    {
      foreach m in modules {
        if (call(m + "_can_run"))
          call(m + "_main");
    }
    There could be some problems implementing call() function since it may return any type and can have exactly 1 or more arguments of any type.
    My KoLmafia script repository: gitweb, snapshot in tar.gz archive

  7. #17
    Member
    Join Date
    Apr 2007
    Location
    Russia
    Posts
    63

    Default Re: Discussion: Standards in relay over-ride scripts

    [quote author=holatuwol link=topic=1538.msg7220#msg7220 date=1203146869]
    The idea would be to make it so that instead of making a set number of scripts work on one page, make it so every script can run on every page.[/quote]

    In this case I would like to know current page. Like, "fight.php", "choiceadv.php", "sewer.php", etc... In short, I would need something like RelayRequest.getPath() in ASH library.
    My KoLmafia script repository: gitweb, snapshot in tar.gz archive

  8. #18
    Senior Member
    Join Date
    Mar 2006
    Posts
    729

    Default Re: Discussion: Standards in relay over-ride scripts

    [quote author=raorn link=topic=1538.msg7577#msg7577 date=1205329215]
    There could be some problems implementing call() function since it may return any type and can have exactly 1 or more arguments of any type.
    [/quote]

    The quote above may very well say it all.

    [quote author=raorn link=topic=1538.msg7661#msg7661 date=1206053538]
    In this case I would like to know current page. Like, "fight.php", "choiceadv.php", "sewer.php", etc... In short, I would need something like RelayRequest.getPath() in ASH library.
    [/quote]

    I second that notion. I occasionally create my own pages, and in order to link to such pages I have to modify another page. This currently requires 2 (or more) scripts to achieve. With the concept model, both pages could be handled in one script.

  9. #19
    Member
    Join Date
    Apr 2007
    Location
    Russia
    Posts
    63

    Default Re: Discussion: Standards in relay over-ride scripts

    [quote author=efilnikufecin link=topic=1538.msg7531#msg7531 date=1205081394]I disagree with that concept. I actually think that trying to work with that model would lead to more trouble than it is worth when we could easily make a shell script based on the needs of the merging of the 2 scripts.[/quote]

    Making merging shell-script requires lot of hand-working and manual editing. Why do it myself, if machine can do it easier? I've been working with this model for a while and this is what I have in mind:

    1. One script may be executed on different pages. So it must tell Mafia on which pages it would run.
    2. Furthermore, script would like to know, for which page it is being called. Mafia should pass page name to script.
    3. More than one script may be executed on a given page. So, script doesn't need to call visit_url(), but accept page text as an argument.
    4. Page, on which script is working, doesn't need to exist if script renders page by itself. In this case Mafia should not call visit_url(), but use script-provided functions (see my script_settings.ash).
    5. Before sending request to game server, script may want to check how would this request be sent. In this case script would like to make different request(s) to game server (see fight_disco_combos.ash) or modify it's internal settings (fight_buttons.ash).

    With suggested implementation (greasemonkey-style) it's unclear who and when should call visit_url() and how can one avoid calling visit_url() when it's not needed. It's a bit unclear, what would happen if one script would like to make some throw_item() or use_skill() requests, based on form_field()s.

    So I'm back to 2-call suggestion:

    For each registered script call "preaction" function with "page name" argument that may return page text until some script returns anything. If no script returns page text, call visit_url(), otherwise use page text returned from first successful script. Then for each script call "render" function (main()) with "page name" and "page text" arguments, collect modified page and pass it to next script.

    I really, Really, REALLY need 2 calls to script. Please, think about it. Relay override is very powerful and useful feature and I don't want it to be nerfed.
    My KoLmafia script repository: gitweb, snapshot in tar.gz archive

  10. #20

    Default Re: Discussion: Standards in relay over-ride scripts

    Nerfed? I thought a nerf was a change that decreased the power or effectiveness of something, usually something that was overpowered to begin with. Can you nerf something by deciding not to make it more powerful? It doesn't seem to fit with the meaning of the word to me.

Similar Threads

  1. continuationState and relay scripts
    By roippi in forum Scripting Discussion
    Replies: 17
    Last Post: 09-27-2014, 03:37 PM
  2. Relay override scripts have never worked for me. Help?
    By quechanmok in forum Community Support
    Replies: 15
    Last Post: 08-07-2013, 06:49 PM
  3. Relay Scripts Post-SVN
    By bumcheekcity in forum Relay Override Scripts
    Replies: 5
    Last Post: 06-01-2013, 10:27 AM
  4. Work in progress relay over-ride questions
    By efilnikufecin in forum Community Support
    Replies: 0
    Last Post: 06-09-2008, 05:18 AM
  5. Re: Discussion of Standards
    By Presto Ragu in forum Community Support
    Replies: 2
    Last Post: 03-30-2006, 07:24 PM

Posting Permissions

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