Welcome to the Achaea Forums! Please be sure to read the Forum Rules.

Matching text with JavaScripting

I am testing custom JavaScripts in Nexus, I've obviously got triggers that run when certain words are matched however I'm wanting it to run a script that continues to look and match other phrases within the same trigger.
So as a basic idea. Attacking the target, if it's still alive continue to attack after balance is restored, if it's slain to stop.
At the moment it stops but only because the target is no longer there. I want it to match the slain message rather than being on an loop until it can't match.
Can anyone give some advise to a very basic user lol :-)

Comments

  • TaelTael Member Posts: 1,197 @ - Epic Achaean
    You probably want two triggers. The easiest way to do this would be to have one trigger on the hit line that adds your attack command to your serverside queue and a second trigger on the slain line that clears your queue.
  • EldEld Member Posts: 3,946 @@ - Legendary Achaean
    If you do find yourself wanting to match text within a string, you can use the string.find and string.match functions. But as Tael says, in this case you'll wasn't separate triggers. Each trigger only looks at the text from one line at a time, so from the code for a given trigger, you won't have access to text that comes on later lines.
  • TaelTael Member Posts: 1,197 @ - Epic Achaean
    If you want to match text within a game message, the answer is generally using regex in the trigger, not using string.find or string.match.
  • EryliseErylise Member Posts: 5
    within the Nexus client we have tried executing a script with string.match and string.find and it came up with ReferenceError: 'string' is undefined
  • TaelTael Member Posts: 1,197 @ - Epic Achaean
    edited April 2016
    The string functions are defined on the string prototype in JavaScript and there's no global String object with methods to call.

    If you want to do a string find, you do it like this: "this is a string".search(/is ?/);

    That will find the regex /is ?/ in your string. You can also use indexOf if you don't need a regular expression, like: "this is a string".indexOf("is");

    And they work the same way with variables containing strings:

    let my_string = "this is a string";
    my_string.indexOf("is");

    If you want to know whether something is in a string, you can test it like this:

    if (my_string.indexOf("is") !== -1) {do_something();}

    indexOf returns the position in the string if it found the thing or -1 if it didn't. So if it isn't equal to -1, the thing is in the string.

    But, again, the thing you're describing is a thing you do with two triggers. A single trigger can only see one line of text and you need to deal with two. It's possible, in a really convoluted way, to get the whole block of text from a message with all the lines, and actually test the strings in each line, but there's just no reason to do that here. The thing here is to use two triggers.
  • EryliseErylise Member Posts: 5
    Thanks guys. Just ended up doing two triggers. Was more of an experiment to see if multiple matches could be made within the one trigger using scripting :). Thanks for taking the time and the advice, was much appreciated
  • TaelTael Member Posts: 1,197 @ - Epic Achaean
    edited April 2016
    It's definitely possible, just sort of cumbersome.

    If you want to do triggers with multiple lines, you need to get the block - I can't check right now but I think the relevant variable is called current_block and I'm pretty sure you can access it within the scripts of triggers.

    You can also use an onBlock "function" that works like onLoad or onGMCP and do a string search or a regex search on each line of current_block (if you call console.log(current_block) and look at your JavaScript console (google how to open it for your browser), you can see the structure of the current_block object, which isn't in the documentation). Doing it that way would be functionally equivalent to writing your own trigger system from scratch, but it would let you pretty easily write multi-line triggers.

    (Which actually, now that I think about it, would be a fine way to add temptriggers to Nexus...huh, I might have to do that.)
  • JhuiJhui Member Posts: 1,958 @@ - Legendary Achaean
    current_block was bugged last time I tried to use it
    image
Sign In to Comment.