HTML5 Client Questions and Such

1911131415

Comments

  • Having trouble highlighting stuff.  Here's an example:

    ^{\w+} takes some {\w+} from a vial and rubs it on {\w+} legs.

    It's set as a regular expression.  I've looked at a ton of examples and the only thing I can think that I'm not doing is a $ at the end? 

    ~Kresslack's obsession~
  • Nevermind, fixed it. 
    ~Kresslack's obsession~
  • edited November 2014
    Sybilla said:
    How do I set up a trigger to capture targets called over a channel (such as Party)?

    Currently in Mudlet I have this:



    Trigger name: Autotarget
    
    Trigger text 1-4 (all perl regex):
    ^\(Party\): (\w+) says, "Target: (.*)\."$
    ^\(Party\): (\w+) says, "Target (.*)\."$
    ^\(Party\): (\w+) says, "TARGET (.*)\."$
    ^\(Party\): (\w+) says, "Targeting: (.*)\."$
    ^\(Party\): (\w+) says, "TARGET: (.*)\."$
    Script:
    target = matches[3]
    echo("\nWe're killing " ..target.. ", Boss.")

    HTML5 client doesn't allow for multiple trigger lines in one, I figure I'll just have to create one trigger each, that's fine, but I can't get it to work with this example:



    Trigger name: Party Target
    
    Trigger text (Regular expression):
    ^\(Party\): (\w+) says, "Target: (\w+)\."$
    Execute script:
    send_direct("st " + args[1]);
    send_direct("ih");

    (I added send_direct("ih") to see whether it was working at all, but no avail).

    Originally tried client.send_direct, and I had the (.*) instead of (\w+) for the target, but neither seemed to be doing anything.

    What am I missing?

    This is pretty old, but it doesn't look like anyone ever answered you. You can write all of those lines in a single regular expression (and it'll be a lot more efficient to boot).

    You want something like:

    ^\(Party\): \w+ says, "T(?:arget)|(?:ARGET)(?:(?:ing)|(?:ING))?:? (\w+)\."$


    So you're matching the beginning of the line, then "(Party): ", then one or more letters (the name of the speaker, which doesn't need parentheses around it since you aren't actually using the match that generates anywhere), then ' says, "T', then either "arget" or "ARGET" (the | means "or", the ?: makes those groups non-capturing, so they don't show up in the matches table), then either "ing" or "ING" but either one is optional (that's what the ? after it means), then an optional ":", then a space, then one or more letters (the called target, which is going to end up as args.match[0]), then '."', then the end of the line.

    JavaScript is obnoxious in that it doesn't let you specify case (in)sensitivty for particular spans, so you have to do it by hand like this.

    I don't know for certain why it wasn't executing at all, but it might be using args rather than args.match, which is where matches are stored according to the documentation page.
  • I fixed it awhile ago, used parentheses instead of braces.
    ~Kresslack's obsession~
  • Addama said:
    I fixed it awhile ago, used parentheses instead of braces.
    He was responding to Sybilla's question on the previous page, not yours.
  • Tael said:
    Sybilla said:
    How do I set up a trigger to capture targets called over a channel (such as Party)?

    Currently in Mudlet I have this:



    Trigger name: Autotarget
    
    Trigger text 1-4 (all perl regex):
    ^\(Party\): (\w+) says, "Target: (.*)\."$
    ^\(Party\): (\w+) says, "Target (.*)\."$
    ^\(Party\): (\w+) says, "TARGET (.*)\."$
    ^\(Party\): (\w+) says, "Targeting: (.*)\."$
    ^\(Party\): (\w+) says, "TARGET: (.*)\."$
    Script:
    target = matches[3]
    echo("\nWe're killing " ..target.. ", Boss.")

    HTML5 client doesn't allow for multiple trigger lines in one, I figure I'll just have to create one trigger each, that's fine, but I can't get it to work with this example:



    Trigger name: Party Target
    
    Trigger text (Regular expression):
    ^\(Party\): (\w+) says, "Target: (\w+)\."$
    Execute script:
    send_direct("st " + args[1]);
    send_direct("ih");

    (I added send_direct("ih") to see whether it was working at all, but no avail).

    Originally tried client.send_direct, and I had the (.*) instead of (\w+) for the target, but neither seemed to be doing anything.

    What am I missing?

    This is pretty old, but it doesn't look like anyone ever answered you. You can write all of those lines in a single regular expression (and it'll be a lot more efficient to boot).

    You want something like:

    ^\(Party\): \w+ says, "T(?:arget)|(?:ARGET)(?:(?:ing)|(?:ING))?:? (\w+)\."$


    So you're matching the beginning of the line, then "(Party): ", then one or more letters (the name of the speaker, which doesn't need parentheses around it since you aren't actually using the match that generates anywhere), then ' says, "T', then either "arget" or "ARGET" (the | means "or", the ?: makes those groups non-capturing, so they don't show up in the matches table), then either "ing" or "ING" but either one is optional (that's what the ? after it means), then an optional ":", then a space, then one or more letters (the called target, which is going to end up as args.match[0]), then '."', then the end of the line.

    JavaScript is obnoxious in that it doesn't let you specify case (in)sensitivty for particular spans, so you have to do it by hand like this.

    I don't know for certain why it wasn't executing at all, but it might be using args rather than args.match, which is where matches are stored according to the documentation page.
    After testing this myself, it looks like the documentation is misleading and it is in fact args, not args.matches. You're going to want args[1] in my example, since args[0] is the entire line. In the original script, args[1] was going to give you the person calling the target (the first capture group), not the target they called.
  • I have a question: how do I do coloured printing?

    It seems relatively straightforward to do highlighting of parsed lines, but I have a trigger that prints a line and I want to print the line colored red so I don't miss it.
  • And a second question (this is why the 15 minute edit limit is silly):

    I have a Package called "General". Inside this package is a trigger called "HuntingRepeat". Also inside this package is an alias. That alias runs the following script:

    var toDisable = client.reflex_find_by_name('trigger', 'HuntingRepeat');
    client.reflex_disable(toDisable);

    This doesn't work. I've tried everything I can think of to get it to work (including the very poorly documented optional arguments for client.reflex_disable, which the help page mentions but doesn't actually define in any way), but no dice.
  • Figured out the answer to the second question: it has to be client.reflex_find_by_name('trigger', 'HuntingRepeat', true, false, 'General')

    Still can't figure out how to print text in different colours and also how to get triggers to print the text AFTER the triggering line rather than before it.
  • And to really continue my spam here: can we get the name of whatever incredible function hides the prompt, but let's it appear in scrollback?

    I want to use that so, so badly to gag queue messages, but keep them in the scrollback.
  • TectonTecton The Garden of the Gods
    client.display_notice('Some text', 'white'); 

    should do what you're after
  • Lovely! Thanks!

    Now I have a new, very frustrating problem. My map is gone! No matter what I do, I just see NO MAP AVAILABLE. I've tried restarting the client, disabling all of my scripts, clearing my cache, restarting Chrome, restarting the whole computer and LAN, no dice. It disappeared right around the time of the server resets.

    The upside of this is that it's made me really appreciate how nice that map really is. I've only been using it for about a week and life is already so hard without it.
  • Disregard, I am an idiot.

    I was blind (I'm not really sure how) - and apparently you can see room descriptions while blind?
  • There's a few "quirks" with the client, for example the Room window in the UI will show me people who are shrouded even if I don't have thirdeye up, which is super-useful for fighting Serpents and Alchemists.

    On the other hand, the UI window also sometimes takes a nap, so I'm often assuming that I'm with my party and don't know they've all left until I LOOK to update the window.
    ~Kresslack's obsession~
  • Okay: I'm trying to script something that highlights Sawbones lines different colors, so like green for not prepped, yellow for damaged, red for fully prepped.  No matter how I try to capture it in regex, though, I never get a match.  I think it might have to do with the variable number of spaces between the limb name and the limb status.

    Has anybody else had this problem?
    ~Kresslack's obsession~
  • A variabe number of spaces? Interesting.

    If it is the case, you can resolve it with
    \s+
    in your regex, which is "1 or any number of consecutive spaces".


    image
  • Addama said:
    Okay: I'm trying to script something that highlights Sawbones lines different colors, so like green for not prepped, yellow for damaged, red for fully prepped.  No matter how I try to capture it in regex, though, I never get a match.  I think it might have to do with the variable number of spaces between the limb name and the limb status.

    Has anybody else had this problem?
    I've never had sawbones, can you post the lines?

    Also, the correct way to do a variable number of spaces is to just put a + after a space. \s matches more than just spaces.

    Also, in case anyone is ever reading this, the above regex I had was wrong, or at least needlessly complicated (I think I was sick when I wrote it...), it should be: ^\(Party\): \w+ says, "T(?:arget|ARGET)(?:ing|ING)?:? (\w+)\."$
  • So what I've got is:

    ^(?:Right leg|Left leg|Right arm|Left arm|Torso|Head): \s+ (?:Perfect health|Barely damaged|Lightly damaged|Moderately damaged|Heavily damaged|Crippled)$

    and my script looks like this:

    limbName = args[0];
    limbStatus = args[1];

    if (args[1].match(/Perfect health/)) {
        client.current_line.parsed_line.colorize(1, 2, 'black', 'white');
    }
    if (args[1].match(/Barely damaged/)) {
        client.current_line.parsed_line.colorize(1, 2, 'black', 'green');
    }

    I'm getting a notification that my args[1] is undefined.  I defined the variable in onLoad and did onLoad in the prompt.  Help?
    ~Kresslack's obsession~
  • Take out the ?: in the pattern. Those are used to prevent the group from being captured to use as an argument.
  • Hahah!  IT WORKS.
    ~Kresslack's obsession~
  • Tael said:
    Addama said:
    Okay: I'm trying to script something that highlights Sawbones lines different colors, so like green for not prepped, yellow for damaged, red for fully prepped.  No matter how I try to capture it in regex, though, I never get a match.  I think it might have to do with the variable number of spaces between the limb name and the limb status.

    Has anybody else had this problem?
    I've never had sawbones, can you post the lines?

    Also, the correct way to do a variable number of spaces is to just put a + after a space. \s matches more than just spaces.

    Also, in case anyone is ever reading this, the above regex I had was wrong, or at least needlessly complicated (I think I was sick when I wrote it...), it should be: ^\(Party\): \w+ says, "T(?:arget|ARGET)(?:ing|ING)?:? (\w+)\."$
    I typically use "\s+" instead of " +" because in cases where you're matching an unknown amount of whitespace, you usually don't care whether it's spaces or tabs or whatever else. I'm fairly sure you never get tab characters in lines from Achaea, though, and that all whitespace is just spaces, so the two are functionally identical for triggers. I don't see any reason to prefer " +" over "\s+" unless you actually want to distinguish between different whitespace characters.
  • I'm trying to use arrays in the html5 client. I can store them just fine (they appear as comma-separated strings), but when I retrieve them it gets converted into an array where one character takes up a slot, instead of the whole word. I also can't seem to run any operations to make it into a comma-separated list again. I got going one time but I'm not sure how to do it again.
  • edited December 2014
    Silex said:
    I'm trying to use arrays in the html5 client. I can store them just fine (they appear as comma-separated strings), but when I retrieve them it gets converted into an array where one character takes up a slot, instead of the whole word. I also can't seem to run any operations to make it into a comma-separated list again. I got going one time but I'm not sure how to do it again.
    You should post the code (just pastebin it and post the link). If you're getting single letters, I'm guessing you're not actually indexing the array, you're indexing a string (which is, technically, just an array of characters).
  • Huh, I finally got it working after a long while. This works, but is pretty messy.
  • edited December 2014
    Are you actually needing the game engine to recognise the testarray variable for some reason? If not, there's not reason to be using client.set_variable or any of that. That's where all the complication is coming in. You only need to fiddle with all of the set_variable stuff if you actually need the in-game system know about the variables - and I can't think of any reason you'd need to here.

    Also, you should probably define (and potentially initialise) variables in the onLoad function rather than in aliases.

    You could replace what you have here with:

    In onLoad:
    var testarray;

    In the alias to set the variable:
    testarray = ['Impatience', 'Breach', 'Stupid'];

    In the alias to print the array:
    print(testarray[0]);
    print(testarray[1]);
    print(testarray[2]);
  • So that kind of works like having a global variable that I can refer to anytime? It would cut down a lot on the complexity.
  • edited December 2014
    It isn't kind of, it is a global variable! It's just a totally normal JavaScript variable like in any JavaScript script.

    In JavaScript, the only local variables are variables defined within functions - everything else is global. While an alias might look kinda sorta like a function (and honestly, it probably should just be a function, though neither Mudlet nor the HTML5 client treat it that way), it's actually just a bare piece of code that runs whenever you run the alias. So any time you declare a variable in an alias, it isn't in a function, so the variable gets global scope.

    So if you have "var testarray;" in a trigger or alias, when you run that trigger or alias, it runs the code, which declares the "testarray" global variable. From then on, it's just a matter of using it like you would any global variable (in other aliases or triggers for instance). Generally speaking, you only want to actually define the variable (what the "var" keyword does) once though, so you can just throw the definition into onLoad and it'll define all of your variables once when you log in.

    The potentially confusing part is that there are also "variables" for the game's internal alias engine (the one that doesn't depend on the client at all). These are not JavaScript variables. That's what the client.set_variable stuff is for - manipulating the game's alias engine. The only one you should ever really be dealing with is the "target" variable, and even then most people just ignore it and use their own normal JavaScript target variable (you can end up fiddling with the engine's target variable a little bit - as I have - to be able to retain the tab-targeting though).
  • Excellent. I've gotten it to work fairly well now. Now the harder part: I'm thinking of making a HTML5 affliction tracker so I know what my enemies are having / curing. What is a good general way to look at tracking that and going about it?
  • KlendathuKlendathu Eye of the Storm
    Silex said:
    Excellent. I've gotten it to work fairly well now. Now the harder part: I'm thinking of making a HTML5 affliction tracker so I know what my enemies are having / curing. What is a good general way to look at tracking that and going about it?
    Have a table which contains all of the afflictions you can give, have trigger lines to update this table when you successfully land an affliction (via venom, class skill, etc), have trigger lines to remove afflictions when you see them eat a herb / apply a salve / touch tree / focus / etc. It won't be perfect, but it'll be better than nothing

    Tharos, the Announcer of Delos shouts, "It's near the end of the egghunt and I still haven't figured out how to pronounce Clean-dat-hoo."
  • From a language standpoint, there's literally no reason you couldn't build an affliction tracker as accurate as the ones that exist for Mudlet (or any other client) in the HTML5 client. JavaScript has all of the language features you need. Whether or not you personally have the coding skill required is a different matter. It's probably the most complex problem you'd attempt to solve coding for Achaea.
Sign In or Register to comment.