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.
 Entire forum ➜ MUSHclient ➜ Tips and tricks ➜ How to stop runaway scripts

How to stop runaway scripts

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


Posted by Nick Gammon   Australia  (23,100 posts)  Bio   Forum Administrator
Date Tue 09 May 2006 03:24 AM (UTC)

Amended on Thu 13 May 2021 07:46 PM (UTC) by Nick Gammon

Message
Sometimes when I am writing scripts I inadvertently send them into a loop, which is annoying because you have to force-quit MUSHclient to recover, possibly losing a heap of changes you have been making to worlds or other documents.

This simple timer shown below should fix this problem. It uses the Lua debug "sethook" facility to make a maximum instruction count (in this example 100,000 instructions). If this is reached an error is raised, breaking the loop and returning control to you.

It is done on a timer (I chose 5 seconds) because eventually normal scripting will consume that many instructions. The net effect should be to allow 100,000 instructions every 5 seconds (which should be plenty), but to raise an error if you do more - which is what a loop will tend to do.

An example of a loop which you could use to test it is:


repeat until false


Just copy this and paste into the timers window. This script is written in Lua, I'm not sure whether other languages support something similar.


<timers>
  <timer enabled="y" 
         second="5.00"    
         send_to="12"
>
  <send>

runaway_instruction_limit = 100000

function hook ()
  debug.sethook (hook, "", runaway_instruction_limit)
  error ("Runaway instruction limit reached")
end -- hook

debug.sethook (hook, "", runaway_instruction_limit)

</send>

  </timer>
</timers>


Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.

- Nick Gammon

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

Posted by Dustin   (4 posts)  Bio
Date Reply #1 on Thu 18 Jan 2007 06:43 AM (UTC)
Message
Cannot use parentheses when calling a Sub
Line in error:
debug.sethook (hook, "", runaway_instruction_limit)



Any idea?
Top

Posted by Onoitsu2   USA  (248 posts)  Bio
Date Reply #2 on Thu 18 Jan 2007 07:10 AM (UTC)

Amended on Thu 18 Jan 2007 07:11 AM (UTC) by Onoitsu2

Message
That is an error message related to VB scripting, you will
need to set your world file to use LUA in order to use
this fix that Nick posted, which is something you ought
to do with your other scripts as well, as it is quickly
becoming the strongest language that MC supports.

Laterzzz,
Onoitsu2
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #3 on Thu 18 Jan 2007 07:11 AM (UTC)
Message
You are using Lua, right, not VBScript?


Edit:
D'oh, Onoitsu2 got there while I was writing mine up. :)
Anyhow, yes, what he said.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
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.


18,590 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.