Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Bug reports ➜ Timer and script issue..

Timer and script issue..

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Shadowfyr   USA  (1,791 posts)  Bio
Date Thu 12 Dec 2002 05:05 AM (UTC)
Message
Just create the following script and timer:
<timers>
  <timer name="TGetStatus" script="TGetStatus" minute="20" >
  </timer>
</timers>

sub GetStatus
  call TGetStatus("Ghost")
end sub

sub TGetStatus (Tname)
  world.resettimer "TGetStatus"
  dim inet
  set inet = createobject("InetCtls.Inet")
  inet.Url = "http://www.topmudsites.com/index2.shtml"
  inet.RequestTimeOut = 20
  dim e, f, st, en, test
  world.note "Retrieving... Standby"
  on error resume next
  e = inet.OpenUrl()
  on error goto 0
  dim RegEx, Match, Matches
  set RegEx = New RegExp
  RegEx.Pattern = "<.*Ages.*>"
  set Matches = RegEx.Execute(e)
  for each Match in Matches
    'world.note Match.FirstIndex
    test = "<tr bgcolor=#e1e1fc>"
    st = instrrev(e,test,int(Match.FirstIndex))
    test = "</tr>"
    en = instr(int(Match.FirstIndex),e,test)
    f = mid(e, st, en - st + 5)
    dim temp
    temp = split(f,chr(10))
    'world.note ubound(temp)
    st = instr(temp(1),"<b>")
    en = instr(temp(1),"</b>")
    dim rank, votes
    rank = mid(temp(1),st + 3,en - (st + 3))
    st = instr(temp(6),"size=2>")
    en = instr(temp(6),"</font>")
    votes =  mid(temp(6), st + 7, en - (st + 7))
    world.send "to gossip"
    world.send "Our current ranking is " & rank & " with " & votes & " votes. Vote AoD!"
    world.send "www.topmudsites.com/cgi-bin/topmuds/"
    world.send "  rankem.cgi?action=in&id=aod"
    world.send "."
    'world.note f
    'world.note Match.Value
  next
end sub

If I call GetStatus directly from the command line like /GetStatus, it works and correctly sends the info retrieved from the HTML of that page. However when relying on the timer it went 30 minutes (when the timer was in fact enabled) without ever doing anything. If I ' out the sends and un-rem the world.note ubound(temp) line, as I did to try to run a test with a shorter time, then saved it, it suddenly fired.

Put simply these where the results:

Attempt 1>
Tried: Timer at 20 minutes world.notes a warning that the client will lag from the load and activates a 5 second timer to call the sub.
Result: Sub keeps repeating world.note "Retrieving... Standby" line, assumption is that the temporary 5 second timer is continually firing, instead of firing once.

Attempt 2>
Tried: Change stuff around to use one timer, add a reset to the start in case it also tries to fire over and over.
Result: Time out error, assumed from changing inet.RequestTimeOut = 20 to 10 instead.

Attempt 3>
Tried: Changed TimeOut back to 20, added on error goto next to routine before call to get the HTML.
Result: Trigger never seems to fire.

Attempt 4>
Tried: Adding on error goto 0, in case something later is causing it.
Result: Same as #3.

Something about this code doesn't want to work right with timers and I can't figure out what or why. :p But it does work when called directly. Not sure about triggers or aliases though.
Top

Posted by Shadowfyr   USA  (1,791 posts)  Bio
Date Reply #1 on Thu 12 Dec 2002 05:22 AM (UTC)
Message
Ok.. Another attempt.

Changed these lines>

'world.send "to gossip"
'world.send "Our current ranking is " & rank & " with " & votes & " votes. Vote AoD!"
world.note "Our current ranking is " & rank & " with " & votes & " votes. Vote AoD!"
'world.send "www.topmudsites.com/cgi-bin/topmuds/"
'world.send " rankem.cgi?action=in&id=aod"
'world.send "."

And shortened the time to 5 minutes. The result was>

Retrieving... Standby

But not other output. This is annoying..
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #2 on Sat 14 Dec 2002 10:09 AM (UTC)
Message
The initial timer doesn't seem to be active. See recent posts about resetting a timer. You can't reset an inactive timer. You need to activate it first.

Maybe the OpenUrl doesn't work?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Shadowfyr   USA  (1,791 posts)  Bio
Date Reply #3 on Sun 15 Dec 2002 03:19 AM (UTC)
Message
Well.. The timer I included was disabled.. I had copied it from the timer list 'after' disabling it temporarilly and forgot to put an enable flag back into it when I posted. I have however attempted the use two timers for a warning + delay, a five minute timer to test it easier and a 20 minute timer, all of them produced odd results.

I am uncertain what is failing. I use ##GetStatus to call it (## being what I changed the immediate mode command prefix to) and it works, locking the client up for 10-20 second as it retrieves the page and correctly displays the information. However using the two timers method I got the "Retrieving... Standby" message over and over every second, as though mushclient couldn't figure out if the timer had fired or not and kept trying to execute the sub call over and over. Using only a single timer I get the same message once, but then nothing happens.

You may be right and the OpenUrl() part is failing when the sub is called from a timer, but it only happens when the timer calls it, not through the command window. I have not tried it with aliases or triggers, but if they perform similar calls, I would suspect the same behaviour. It is as though the client when doing a sub call from a timer is interfering with the OpenUrl() command or bailing out of the sub before it completes.

NOTE: I added the world.resettimer "TGetStatus" line specifically to prevent the timer refiring over and over like I got with the previous case. I don't know if it would have done so, but figured that reseting it would make it less likely that I would get spammed by it repeatedly firing if it happened, so I am not certain what would happen if you where to rem out that line.
Top

Posted by Shadowfyr   USA  (1,791 posts)  Bio
Date Reply #4 on Sun 15 Dec 2002 04:33 AM (UTC)
Message
Hmm. It should also be noticed that the mud has finally entered the top 20, so the URL is now http://www.topmudsites.com/.

The previous one will obviously never find a match now. lol
Top

Posted by Shadowfyr   USA  (1,791 posts)  Bio
Date Reply #5 on Sun 15 Dec 2002 08:15 PM (UTC)

Amended on Sun 15 Dec 2002 08:16 PM (UTC) by Shadowfyr

Message
Ok.. The current form of the subs I am using and notes on what changed, etc.:

sub GetStatus 'Called in immediate mode.
  call TGetStatus("Ghost")
end sub

sub TGetStatus (Tname) 'Callable from a timer, but dies when I try (enabled/disabled status of timer does not matter.
  world.resettimer "TGetStatus" 'Added to prevent possible multiple firings as happened on a previous test (not sure of it is/was needed).
  dim inet
  set inet = createobject("InetCtls.Inet")
  ' Changed URL since the top 20 uses the main page.
  inet.Url = "http://www.topmudsites.com/"
  inet.RequestTimeOut = 20
  dim e, f, st, en, test
  world.note "Retrieving... Standby"
  on error resume next
  e = inet.OpenUrl()
  on error goto 0
  dim RegEx, Match, Matches
  set RegEx = New RegExp
  'Changed this pattern, since checking only Ages caught other things.
  RegEx.Pattern = "<.*agesofdespair.*>"
  set Matches = RegEx.Execute(e)
  for each Match in Matches
    test = "<tr bgcolor=#e1e1fc>"
    st = instrrev(e,test,int(Match.FirstIndex))
    test = "</tr>"
    en = instr(int(Match.FirstIndex),e,test)
    f = mid(e, st, en - st + 5)
    dim temp
    temp = split(f,chr(10))
    st = instr(temp(1),"<b>")
    en = instr(temp(1),"</b>")
    dim rank, votes
    rank = mid(temp(1),st + 3,en - (st + 3))
    st = instr(temp(6),"size=2>")
    en = instr(temp(6),"</font>")
    votes =  mid(temp(6), st + 7, en - (st + 7))
    world.send "to gossip"
    world.send "Our current ranking is " & rank & " with " & votes & " votes. Vote AoD!"
    world.send "www.topmudsites.com/cgi-bin/topmuds/"
    world.send "  rankem.cgi?action=in&id=aod"
    world.send "."
  next
end sub
Top

Posted by Shadowfyr   USA  (1,791 posts)  Bio
Date Reply #6 on Mon 16 Dec 2002 01:18 AM (UTC)
Message
Ok.. How about a simplified version of the issue:

<timers>
  <timer name="TGetStatus" script="TGetStatus" enabled="y" minute="3" note="y" active_closed="y" >
  <send>--Timer--</send>
  </timer>
</timers>

sub GetStatus
  call TGetStatus("Ghost")
end sub

sub TGetStatus (Tname)
  a = world.getvariable("tttt")
  a = a + 1
  if a > 3 then
    world.resettimer "TGetStatus"
    world.setvariable "tttt",0
  else
    world.setvariable "tttt",a
  end if
  dim inet
  set inet = createobject("InetCtls.Inet")
  world.note "Object created"
  inet.Url = "http://www.topmudsites.com/"
  inet.RequestTimeOut = 20
  dim e, f, st, en, test
  world.note "Retrieving... Standby"
  on error resume next
  e = inet.OpenUrl()
  on error goto 0
  world.note "Got HTML?"
  world.note "Data: "
  world.note left(e, 70) & " ..."
end sub

This produces:

--Timer--
Object created
Retrieving... Standby
--Timer--
Object created
Retrieving... Standby
--Timer--
Object created
Retrieving... Standby
Got HTML?
Data:
<html>
<head>
<title>Top MUD Sites - mud list, top muds, mud sites, di ...
Got HTML?
Data:
<html>
<head>
<title>Top MUD Sites - mud list, top muds, mud sites, di ...
Got HTML?
Data:
<html>
<head>
<title>Top MUD Sites - mud list, top muds, mud sites, di ...

If I reset the timer the first time (i.e. don't let it fire more than once) I get only:

--Timer--

If however I remove the timer reset completely I end up with:

--Timer--
Object created
Retrieving... Standby
--Timer--
Object created
Retrieving... Standby
--Timer--
Object created
Retrieving... Standby
--Timer--
Object created
Retrieving... Standby
--Timer--
Object created
Retrieving... Standby
--Timer--
Object created
Retrieving... Standby
... ad infinitum ...

It seems to me that the timer tries to call the sub, times out or something due to the long delay loading the HTML, and ends up looping. If I "don't" reset the timer it repeats forever and locks up the client. Letting it repeat 3 times results in it showing the timer go off three times, then the timer gets reset and "'then'" the sub actually gets called 3 times in a row, after which the timer stops firing at all (probably caught in an endless cycle of some sort as happens when you don't reset it). Hope this provides a clearer example of the problem. :p
Top

Posted by Shadowfyr   USA  (1,791 posts)  Bio
Date Reply #7 on Sun 22 Dec 2002 05:03 PM (UTC)
Message
I take it you haven't found a solution to this Nick? :p
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #8 on Sun 22 Dec 2002 10:31 PM (UTC)
Message
I put off looking at it because it looked so complicated. ;)

OK, I see the problem here. In the timer processing it does this:


  1. Check timer list (every second or whatever you specify in the global config)
  2. For each active timer, see if it is time to fire it.
  3. If it is time then:

    1. Count matches (add 1 to timer match count)
    2. Note when fired
    3. Send timer message to world or output window
    4. Call timer script
    5. Update "time to fire" by adding appropriate interval to it. If for some reason this ends up being in the past, reset the timer.
    6. If a one-shot timer, delete it from the timer list



Now here's the bug - for a timer script that takes more than one second to process (eg. invoking your Inet.OpenURL) the "time to fire" hasn't been updated yet. This *shouldn't* matter in a single-threaded application, but in my case a dialog box appeared (couldn't create the object) and dialog boxes are put into another thread. Anyway it seems to me that the solution would be for me to update the "time to fire" immediately it fires, in case something like this happens.

Meanwhile a workaround might be, in the timer script, to disable itself as soon as the script is entered, do your stuff, and then re-enable itself on exit. That should stop the extra calls.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Shadowfyr   USA  (1,791 posts)  Bio
Date Reply #9 on Sun 22 Dec 2002 11:13 PM (UTC)
Message
Hmm. Ok. I'll try that. I had hoped that doing a reset immediately would have that same effect, but it just caused the bloody thing to not do anything at all. :p I figured there might be some sneaky think like that in there though. ;)
Top

Posted by Shadowfyr   USA  (1,791 posts)  Bio
Date Reply #10 on Sun 22 Dec 2002 11:40 PM (UTC)
Message
Hmm. Well doing it that way gives>

--Timer--
Object created
Retrieving... Standby
Got HTML?
Data:
<html>
<head>
<title>Top MUD Sites - mud list, top muds, mud sites, di ...
to gossip
Our current ranking is 6 with 224 votes. Vote AoD!
www.topmudsites.com/cgi-bin/topmuds/
rankem.cgi?action=in&id=aod
.
to gossip
Our current ranking is 6 with 224 votes. Vote AoD!
www.topmudsites.com/cgi-bin/topmuds/
rankem.cgi?action=in
.
--Timer--
--Timer--
--Timer--

Attempting to instead just reset the timer at the end of the sub result in the same:

--Timer--
Object created
Retrieving... Standby
--Timer--
Object created
Retrieving... Standby
--Timer--
Object created
Retrieving... Standby
...

Sigh.. Oh well, was worth a try. :p

Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #11 on Sun 22 Dec 2002 11:51 PM (UTC)
Message
I did say to disable it, not reset it.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Shadowfyr   USA  (1,791 posts)  Bio
Date Reply #12 on Mon 23 Dec 2002 05:03 AM (UTC)
Message
I did disable it in the first instance and renable it later. That was what produced the first valid result followed by:

*Valid result*
-Timer-
-Timer-
-Timer-

Disabling it will work, but after re-enabled, both 'in' the script, through a different script or directly, the result is the above. As soon as the timer is re-enabled it starts screwing up again.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


26,227 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.