Timers Reset In Plugin

Posted by Sediket on Mon 09 May 2022 05:56 PM — 2 posts, 10,671 views.

#0
I came across something weird, when using addxml in a plugin it resets all the timers. I don't know if that's suppose to happen or if I'm doing something wrong, here is a plugin that demonstrates this:


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Monday, May 09, 2022, 12:36 PM -->
<!-- MuClient version 5.06 -->

<!-- Plugin "test" generated by Plugin Wizard -->

<muclient>
<plugin
   name="test"
   id="ae563a798b323a32a21db226"
   language="Lua"
   date_written="2022-05-09 12:36:21"
   requires="5.06"
   version="1.0"
   >

</plugin>


<!--  Get our standard constants -->

<include name="constants.lua"/>

  <script>
    <![CDATA[
require "wait"
require "addxml"	

addxml.timer {  

			name="tank",
			enabled="y",
			minute="20",
			temporary="y",
			send = "var_stop = 1",
			send_to = 12,
		}

addxml.timer {  

			name="dps",
			enabled="y",
			minute="10",
			temporary="y",
			send = "var_stop = 1",
			send_to = 12,
		}


wait.make (function() 
  Note("Time left on timer tank: " .. GetTimerInfo("tank",13))
  Note("Time left on timer dps: " .. GetTimerInfo("dps",13))
  wait.time(4)
  Note("Time left on timer tank: " .. GetTimerInfo("tank",13))
  Note("Time left on timer dps: " .. GetTimerInfo("dps",13))
  wait.time(4)

  addxml.trigger{
    enabled="y",
    name="stop_action_trig",
    match=[[^\/stop$]],
    sequence="90",
    regexp="y",
    one_shot="y",
    send_to='12',
    send="var_action_stop = 1",
  }
  Note("Time left on timer tank: " .. GetTimerInfo("tank",13))
  Note("Time left on timer dps: " .. GetTimerInfo("dps",13))
end)

]]>
  </script>

</muclient>



output:
Time left on timer tank: 1199.9999850523
Time left on timer dps: 599.99952481594
Reinstalled plugin test (ae563a798b323a32a21db226)
Time left on timer tank before addxml: 1195.9744291613
Time left on timer dps before addxml: 595.97398464102
Time left on timer tank after addxml: 1199.9999793945
Time left on timer dps after addxml: 599.99843474943

The last two notes show how the timers were reset after use addxml

edit: This seems to only happen in plugins, for example in the specified external script file under scripts in Configuration this doesn't happen .
Amended on Mon 09 May 2022 06:11 PM by Sediket
Australia Forum Administrator #1
Is there any reason you don't just make the timers once, and then start and stop them? That might work around this issue.

It appears that what you describe is by design (sort of).

The addxml stuff calls a function that is used to load a plugin, except that it loads part of a plugin (ie. a timer in this case).

Then plugin loader then does a "reset all timers" as part of loading so that the timers start in a known way.

A way of working around this would be to use AddTimer and then if necessary follow that by SetTimerOption to set any options that are not directly supported by AddTimer. This does not use the XML loading interface and should not reset other timers.

Template:function=AddTimer
AddTimer

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



Template:function=SetTimerOption
SetTimerOption

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