[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Tips and tricks
. . -> [Subject]  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] Refresh page


Posted by Nick Gammon   Australia  (23,006 posts)  [Biography] 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
[Go to top] top

Posted by Dustin   (4 posts)  [Biography] 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?
[Go to top] top

Posted by Onoitsu2   USA  (248 posts)  [Biography] 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
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] 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
[Go to top] 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.


17,660 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]