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:
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.
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>
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.