mix_relays.ash: "easy" relay override composition

heeheehee

Developer
Staff member
The recent combatfilter script for the CAB got me to actually write and submit a script for you guys :|

Basically, it introduces replacements for visit_url (the 0-argument version), write, and writeln: get_page(), write_page(string), writeln(string). It also introduces finish_page(), which should be called after you've finished calling all the other scripts.

I've also included a piece of sample code composing BatMan Relay with kolcombatfilter. Note: composing these two particular scripts was a bit more involved than I'd hoped, mostly because there were a number of namespace collisions.

A few comments for script authors. Please avoid polluting the global namespace with generic variable names like "results" (and functions called whatever. If you want, you can just stick everything* inside main(), or you can prefix your script's exported functions with "scriptname_"). Please avoid relying too much on the structure of the HTML, since that can potentially change (this manifested with BatMan relay rewriting the head and appending jQuery at the end, so the order of the calls to the main functions actually matters :( --- I'd suggest putting only dependencies like jQuery in the head). Please don't mangle the HTML more than necessary.

* well, mostly everything --- I think it's just combat filters that need to be top-level code.

danke!

(I'd include a screenshot, but I really should have gone to sleep hours ago.)

Instructions for use: install all the files associated with BatMan Relay and kolcombatfilter in the proper directories (clobbering fight.ash as you see fit), then stick fight.ash in your relay/ directory (clobbering fight.ash again) and the other scripts wherever you want (probably scripts/, although I have most of them in relay/. Doesn't make much of a difference, really).

aside: I don't really like that integration requires a custom fight.ash (and renaming of the existing fight.ash files) -- it's not the most inviting interface, especially to people who just want to download files without needing to bust out the ol' text editor to get everything _just_ right. It's still better than trying to merge the two scripts (although to be fair, the vast majority of kolcombatfilter is in the js file, not ASH :p) and maintaining a separate fork.

also, vision: relay overrides in the future look something like this:
Code:
import <mix_relays>

void alternateScriptName()
{
    ... stuff
}


void main()
{
    alternateScriptName();
    finish_page();
}

happy hacking!
 

Attachments

  • batman_fight.ash
    18.1 KB · Views: 44
  • combatfilter_fight.ash
    1.1 KB · Views: 50
  • fight.ash
    155 bytes · Views: 44
  • mix_relays.ash
    802 bytes · Views: 48

lostcalpolydude

Developer
Staff member
A stickied thread in the Relay Browser section suggests the same type of approach for making scripts usable together, by putting everything into functions rather than having the whole script be global.
 

heeheehee

Developer
Staff member
Actually, the only things you "need" to do to use this is change from calling visit_url to get_page, write to write_page, and writeln to writeln_page, and call finish_page in whatever calling script you have. I mean, yes, refactoring isn't that bad, but when you have relay scripts that call write and writeln all over the place, you actually have to put in some effort. With this approach, you could just use a regex search + replace (like perl or sed) to make a script composable.

(also, that thread's been around since 2008, and yet I doubt most scripters here actually follow those practices.)
 
Top