Conflicting Scripts

Posted by Traz on Fri 30 Mar 2018 04:14 AM — 16 posts, 62,524 views.

#0
So I've played around a few different ways and I cannot for the life of me figure out why these two scripts can't go off the same line. I've had it happen with other scripts before but I could usually find some compromise. This one is beyond me and I need help. Both were disabled at the time for editing, but when both activated only one works.


<triggers>
  <trigger
   expand_variables="y"
   group="NecroMLOL"
   keep_evaluating="y"
   match="*[Ki:*]*"
   send_to="12"
   sequence="99"
  >
  <send>local pl = @Pl
local half = @MaxPl * .5
local quarter = @MaxPl * .25
local stop = @MaxPl * .3

if lastTriggerTime == nil or os.time () - lastTriggerTime &gt;=1  then
lastTriggerTime = os.time ()
if pl &gt;= half then
Execute ("powd")
end
end</send>
  </trigger>
</triggers>



<triggers>
  <trigger
   expand_variables="y"
   group="NecroM"
   keep_evaluating="y"
   match="[Pl:*][Ki:*]*"
   send_to="12"
   sequence="98"
  >
  <send>require "wait"
  if @Ki &lt;= 50000 then
  if lastTriggerTime == nil or os.time () - lastTriggerTime &gt;= 5 then
wait.make (function ()
  lastTriggerTime = os.time ()
Execute ("nmoff")
wait.regexp ("^Blood splatters as (.*?) soul fades away\.$")
wait.time (3)
Execute ("sense half-dead")
wait.time (3)
Send ("--")
Send ("--")
Execute ("senzu")
Send ("gtell sense me")
wait.time (10)
Execute ("nmon")
end)
end
end</send>
  </trigger>
</triggers>
Australia Forum Administrator #1
Can you expand this by stating which trigger works?

Also post some example output that these triggers should match on? Then we can set up a test of the problem.
#2
They both work, they just don't work together. Right now, the first one is working when both are activated.

The full line they match on is:

[Pl:688,894][Ki:229,083][3% EXP][Fatigue: 22%][HT][FM][Flying]

When Ki is below 50k, the second one should run. When Pl is more than half, which it is right now, the first one should run to make it less than half. I pull the @MaxKi variable from the score sheet that I have set on a timer every 10 minutes.
Amended on Fri 30 Mar 2018 11:57 AM by Traz
USA Global Moderator #3
I see a few potential issues...

1) You're gatekeeping execution on whether lastTriggerTime is nil or some arbitrary time in the past, but the earlier trigger sets lastTriggerTime to the current time, which means that the next one will always be blocked if @Ki < 50000.

2) Arbitrary times in the past are rarely what you actually want to check against.

3) Where is @Ki set?

4) Since both of those triggers run on the same input, they should really just be one trigger with multiple steps.
Amended on Fri 30 Mar 2018 02:23 PM by Fiendish
#4
1) I know of no way around that, it's the only method I have learned thus far

3) @Ki is set to the current prompt, so whatever the ki is at in the prompt I showed, every time a command is entered, it is updated.

4) I'm unsure how to make a script do two different things for different criteria like that.
USA Global Moderator #5
Traz said:

1) I know of no way around that, it's the only method I have learned thus far

Method for what? You've asked why they don't both work, and I'm telling you at least one reason why they won't both work.

Quote:
3) @Ki is set to the current prompt, so whatever the ki is at in the prompt I showed, every time a command is entered, it is updated.

How many triggers do you have for your prompt line? Please show all of them. So far nothing you've shown sets Ki.
Amended on Fri 30 Mar 2018 05:21 PM by Fiendish
#6
Method for making sure a trigger doesn't spam the shit out of me.

These are all the triggers that are active for this group:


<triggers>
  <trigger
   expand_variables="y"
   group="NecroM"
   keep_evaluating="y"
   match="*[Fatigue: *%]*"
   send_to="12"
   sequence="100"
  >
  <send>if @Fatigue &gt;= 40 then
  if lastTriggerTime == nil or os.time () - lastTriggerTime &gt;= 30 then
  lastTriggerTime = os.time ()
Execute ("drink1")
Execute ("drink2")
end
end</send>
  </trigger>


  <trigger
   expand_variables="y"
   group="NecroMLOL"
   keep_evaluating="y"
   match="*[Ki:*]*"
   send_to="12"
   sequence="99"
  >
  <send>local pl = @Pl
local half = @MaxPl * .5
local quarter = @MaxPl * .25
local stop = @MaxPl * .3

if lastTriggerTime == nil or os.time () - lastTriggerTime &gt;=1  then
lastTriggerTime = os.time ()
if pl &gt;= half then
Execute ("powd")
end
end</send>
  </trigger>


  <trigger
   expand_variables="y"
   group="NecroM"
   keep_evaluating="y"
   match="[Pl:*][Ki:*]*"
   send_to="12"
   sequence="98"
  >
  <send>require "wait"
  if @Ki &lt;= 50000 then
  if lastTriggerTime == nil or os.time () - lastTriggerTime &gt;= 5 then
wait.make (function ()
  lastTriggerTime = os.time ()
Execute ("nmoff")
wait.regexp ("^Blood splatters as (.*?) soul fades away\.$")
wait.time (3)
Execute ("sense half-dead")
wait.time (3)
Send ("--")
Send ("--")
Execute ("senzu")
Send ("gtell sense me")
wait.time (10)
Execute ("nmon")
end)
end
end</send>
  </trigger>


  <trigger
   enabled="y"
   group="Variables"
   keep_evaluating="y"
   match="[Pl:*][Ki:*]*[*: *%]*"
   send_to="12"
   sequence="100"
  >
  <send>pl1 = ("%1")
pl2 = string.gsub (pl1, (","), "")
ki1 = ("%2") 
ki2 = string.gsub (ki1, (","), "") 
SetVariable ("Pl", pl2) 
SetVariable ("Ki", ki2) 
SetVariable ("Fatigue", "%5")</send>
  </trigger>
</triggers>
Amended on Fri 30 Mar 2018 06:59 PM by Traz
Australia Forum Administrator #7
   match="[Pl:*][Ki:*]*"

and:

  match="*[Ki:*]*"

So you are trying to match on [Ki:*] possibly preceded by [Pl:*]?

The easiest thing is to make that a regular expression and check for both in one trigger, eg.

   match="^(?:\[Pl:(.*?)\])?\[Ki:(.*?)\]"
   regexp="y"

See regular expressions for the meaning of those symbols.

Basically:

^     <-- start of line
(?:   <-- start of group without a capture
\[Pl: <-- matches [Pl
(.*?) <-- capture the Pl value, non-greedy
\]    <-- matches ]
)?    <-- end of group, group is optional
\[Ki: <-- matches [Ki
(.*?) <-- capture the Ki value, non-greedy
\]    <-- matches ]
Amended on Fri 30 Mar 2018 08:53 PM by Nick Gammon
#8
Ok, but they don't go off at the same time, so I don't know how putting them in the same trigger would even work.
Australia Forum Administrator #9

What do you mean, the don’t go off at the same time?

A trigger matching:

[Pl:*][Ki:*]*

would also match

*[Ki:*]*

because the first asterisk could match [Pl:*]

Amended on Sat 31 Mar 2018 03:53 AM by Nick Gammon
#10
One goes off when ki is less than 50,000, the other goes off when pl is more than half. They don't usually occur at the same time, though they could.
Australia Forum Administrator #11

Your terminology is confusing me. Both triggers will fire, regardless of the numerical value of Ki, as there is no test for that in the trigger match line.

Perhaps if we can step back from what you think the solution is, to describing your problem in more detail?

#12
One trigger should go off only when Ki is less than 50000.

The other trigger should only go off when Pl is more than half.

How I have them set up initially, they both work when the other is not enabled. Only one works when both are enabled.
I just need both of them to work as stated above while both are enabled.
Amended on Sat 31 Mar 2018 06:30 PM by Traz
Australia Forum Administrator #13
You don't get to make conditional triggers like that (unless you mean that is the way the MUD sends things to you - is that what you mean?).

Can you copy/paste some example output from the MUD so we know what you are talking about?

Quote:

How I have them set up initially, they both work when the other is not enabled. Only one works when both are enabled.
I just need both of them to work as stated above while both are enabled.


In particular post messages that demonstrate that situation, so we can reproduce it.
Australia Forum Administrator #14
Traz said:

One trigger should go off only when Ki is less than 50000.


Do you mean "match" (rather than "go off")? Tomatoes go off if you don't eat them before they start to mould. Triggers match an incoming string.

Inside the trigger (once it matches) the code may decide to do this or that. It isn't clear to me whether you mean you want the trigger to match if Ki is less than 50000, or whether some code inside the trigger is supposed to do something different if Ki is less than 50000.
#15
I found a way to make it work. Thanks.