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 :-)
0
Comments
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.
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.)