Send looping

Posted by Green on Thu 24 May 2018 08:27 PM — 6 posts, 21,979 views.

#0
Trying to send an alias to the world when health is low...
i changed the send part so there are no other alis/trigs like it.. still spams / loops over and over.. when i comment out the send.. it works fine.


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="PROMPT"
   keep_evaluating="y"
   match="^H\: (.*?)\/(.*?) S\: (.*?)\/(.*?) Favors\: (.*?)\/(.*?)$"
   name="HPmon2"
   omit_from_output="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send> hp = %1
 maxhp=%2
 stm=%3
 maxstm=%4
 favor=%5
 maxfavor=%6
 

-- Step #2: Info bar.
-- Step #2A: Basic setup + HP monitor.
ShowInfoBar (Visible)
InfoClear ()
InfoBackground ("black")
InfoFont ("FixedSys", 9, 0)

InfoColour ("lime")
if (hp &lt; (maxhp / 2) ) then
  InfoColour ("red")  
end
Info ("HP: ", hp, "/", maxhp)

-- Step 2B: FTG monitor.
InfoColour ("lime")
if (stm &lt; (maxstm / 2) ) then
  InfoColour ("red")   
end
Info ("   Stm: ", stm, "/", maxstm)

-- Step 2C: Favor monitor
InfoColour ("lime")
if (favor &lt; (maxfavor / 2) ) then
  InfoColour ("red")  
end
Info ("   Favor: ", favor, "/", maxfavor)

if (hp &lt; (maxhp / 2) ) then  
   -- Send ("lowHPZ")  -- ***** loops from here?
ColourNote ("white", "blue", "LOW F@CKING HP!")

end
</send>
  </trigger>
</triggers>

Amended on Thu 24 May 2018 08:36 PM by Green
Australia Forum Administrator #1
Probably your send is causing another status line to appear, so you notice your HP are low and you do another send, and get another status line, and so on.

You want some sort of test to only send (say) every 30 seconds.
Australia Forum Administrator #2
For example:


if hp < (maxhp / 2)  then  
  if last_time_sent == nil or os.time () - last_time_sent > 20 then
    last_time_sent = os.time ()  -- remember when we sent
    Send ("lowHPZ")   -- send the command
    ColourNote ("white", "blue", "LOW F@CKING HP!")
    end -- if 20 seconds have passed
end  -- if low HP
#3
ok thanks, i'll check it and see what happens :)
#4
so...
i tried your mod, and it stopped the looping ty!
a player said to use Execute ...to send an alias, instead of send, and it works good :)

here is the hp prompt trigger

<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="PROMPT"
   keep_evaluating="y"
   match="^H\: (.*?)\/(.*?) S\: (.*?)\/(.*?) Favors\: (.*?)\/(.*?)$"
   name="HPmon2"
   omit_from_output="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send> hp = %1
 maxhp=%2
 stm=%3
 maxstm=%4
 favor=%5
 maxfavor=%6
 

-- Step #2: Info bar.
-- Step #2A: Basic setup + HP monitor.
ShowInfoBar (Visible)
InfoClear ()
InfoBackground ("black")
InfoFont ("FixedSys", 9, 0)

InfoColour ("lime")
if (hp &lt; (maxhp / 2) ) then
  InfoColour ("red")  
end
Info ("HP: ", hp, "/", maxhp)

-- Step 2B: FTG monitor.
InfoColour ("lime")
if (stm &lt; (maxstm / 2) ) then
  InfoColour ("red")   
end
Info ("   Stm: ", stm, "/", maxstm)

-- Step 2C: Favor monitor
InfoColour ("lime")
if (favor &lt; (maxfavor / 2) ) then
  InfoColour ("red")  
end
Info ("   Favor: ", favor, "/", maxfavor)

if (hp &lt; (maxhp / 2)  ) then  
  if (last_time_sent == nil or os.time () - last_time_sent &gt; 20) then
    last_time_sent = os.time ()  -- remember when we sent
    Execute ("lowHP")   -- send the command
    ColourNote ("white", "blue", "LOW FeCKING HP!")
    end -- if 20 seconds have passed
end  -- if low HP
</send>
  </trigger>
</triggers>




also, as a side note...
i tried to use a toggle instead of checking the time, but
couldn't get it to work... if a variable is not there, it should be auto created?



if (hp < (maxhp / 2) and tonumber(GetVariable("hpTOG")) == 0 ) then  
    Execute ("lowHP") 
    SetVariable ("hpTOG", 1)
ColourNote ("white", "blue", "LOW FeCKING HP!")

end
if (hp == maxhp  and tonumber(GetVariable("hpTOG")) == 1 ) then  
   
    SetVariable ("hpTOG", 0)
ColourNote ("white", "blue", "Healed!")

end
Amended on Fri 25 May 2018 02:15 PM by Green
Australia Forum Administrator #5
Template:function=GetVariable
GetVariable

The documentation for the GetVariable script function is available online. It is also in the MUSHclient help file.



If GetVariable is called for a variable that doesn't exist, it returns nil in Lua. This is because any other value (eg. zero) could be a valid value to store in a variable.

You don't have to use client variables anyway for simple things like toggles, because they don't need to be stored for next time.

In my example code:


if last_time_sent == nil ...


That first tests if last_time_sent is nil (which means that variable wasn't created yet).

In your code:


tonumber(GetVariable("hpTOG"))


The function tonumber returns nil if passed nil, so you could have tested for that. eg.


hpTOG = tonumber (GetVariable("hpTOG"))

if hp < (maxhp / 2) and 
  (hpTOG == nil or hpTOG == 0) then
...