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
➜ General
➜ Errors
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Shadoweave
(42 posts) Bio
|
Date
| Sat 22 Dec 2007 08:19 PM (UTC) |
Message
| I was wondering if there is a way to prevent the error window that appears every time something went wrong with my script file. Yes, I have checked the "Note errors" option on the scripts page.
And I have another question. My prompt function calls other functions when it executes, a function to heal afflictions that are cured by drinking potions, one to heal by eating herbs, one to heal by applying salves, and so one. If one of these functions encounters an error, my entire prompt function is disabled and I won't be able to cure using the other functions. So I was wondering if there is a way (a plugin maybe?) so that if one of the curing functions encounters and error, all my other function would still work. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sat 22 Dec 2007 08:47 PM (UTC) Amended on Sat 22 Dec 2007 08:49 PM (UTC) by Nick Gammon
|
Message
|
Quote:
I was wondering if there is a way to prevent the error window that appears every time something went wrong with my script file. Yes, I have checked the "Note errors" option on the scripts page.
You shouldn't see a dialog box appearing - is that what you meant? Or are you referring to a plugin error? A separate window appears when loading a plugin, that is part of the loading process.
Quote:
So I was wondering if there is a way (a plugin maybe?) so that if one of the curing functions encounters and error, all my other function would still work.
Yes you can do that with protected calls in Lua. Below is an example, I make a trigger call Trigger_Stub which simply does a protected call of the Main_Trigger function (which would have been your original trigger). In that I deliberately introduce a runtime error.
The stub function detects the error and displays an error message. However as far as MUSHclient is concerned the trigger fired OK, and thus the script is not disabled.
This is a simple example, if you had lots of triggers you could make it more efficient, for example by having a table that maps the trigger name to the actual function to be called by the stub routine.
The stub routine could look up the trigger name in a table, call the correct function in protected mode, and display an error if it occurs.
-- this is the original trigger function
function Main_Trigger (name, line, wildcards)
a = nil + b -- deliberate error
end -- function Main_Trigger
-- make your trigger call this instead ...
function Trigger_Stub (name, line, wildcards)
ok, err = pcall (Main_Trigger, name, line, wildcards)
if not ok then
ColourNote ("white", "red", err)
end -- if error on function call
end -- function Trigger_Stub
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Worstje
Netherlands (899 posts) Bio
|
Date
| Reply #2 on Sun 23 Dec 2007 06:50 AM (UTC) |
Message
| Nick, I am afraid the Note Errors does not seem to suppress all dialogboxes. I found this out around a week ago when I was on a world I rarely use, and I did have Note Errors checked. The plugin in question was a Lua plugin, so I maybe the different handling for Lua code is something you forgot to adjust when adding the feature?
I didn't test it much and planned to report it, but I forgot about it. I haven't had much reason to find out what caused it since I managed to squash the bug in question, but still - it was definately there. | Top |
|
Posted by
| Shadoweave
(42 posts) Bio
|
Date
| Reply #3 on Sun 23 Dec 2007 09:28 AM (UTC) Amended on Sun 23 Dec 2007 10:55 AM (UTC) by Shadoweave
|
Message
|
Quote:
You shouldn't see a dialog box appearing - is that what you meant? Or are you referring to a plugin error? A separate window appears when loading a plugin, that is part of the loading process.
I was referring to dialog boxes that appear if I encounter a runtime error, something like this:
Error number: 0
Event: Run-time error
Description: [string "Script file"]:4864: attempt to concatenate field '?' (a nil value)
stack traceback:
[string "Script file"]:4864: in function 'scan_focus'
[string "Script file"]:4591: in function <[string "Script file"]:4493>
Called by: Function/Sub: prompt called by trigger
Reason: processing trigger "Prompt"
With a Close and Copy details buttons.
EDIT: pcall is exactly what I needed, it works great, thank you. One question, though, does it have a noticeable impact on speed?
| Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #4 on Sun 23 Dec 2007 07:20 PM (UTC) |
Message
|
Quote:
I am afraid the Note Errors does not seem to suppress all dialogboxes.
I have looked at the source and can't see a place where it is overlooked. Can you reproduce it for me?
Quote:
pcall is exactly what I needed, it works great, thank you. One question, though, does it have a noticeable impact on speed?
I doubt if the impact on speed would be great. MUSHclient does a pcall anyway, which is how it can report errors, so you would be adding another one. One more instruction on top of the dozens your script will do anyway is probably insignificant. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Shadoweave
(42 posts) Bio
|
Date
| Reply #5 on Sun 23 Dec 2007 08:51 PM (UTC) Amended on Sun 23 Dec 2007 08:52 PM (UTC) by Shadoweave
|
Message
|
Quote:
I have looked at the source and can't see a place where it is overlooked. Can you reproduce it for me?
This is the easiest example I could make based on what usually happens in my script file when I get the error windows. Might be some other easier way to reproduce it, but I didn't find it:
test_queue = {
"slickness",
"addiction",
"artery_leftarm",}
test_flag = {}
test_aff = {}
test_flag.slickness = "calamus"
test_aff.slickness = "calamus"
function test ()
pri = 100
for aff, cure in pairs (test_aff) do
for k, a in ipairs (test_queue) do
if a == aff then
aux = k
break
end --if
end --for
if (aux < pri) and (test_flag[aff] == nil) then --if I have already tried to cure the affliction, I don't try again
pri = aux
to_cure = aff
end --if
end --for
Send ("eat "..test_aff[to_cure]) --this is where the error is, I have nothing to cure since the flag for slickness in not nil
end --function
<alias
script="test"
match="^test$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
>
</alias>
Send "test" to the mud and you will get an error window. And another thing I have found, if you put the name of the script (in this case "test") and the script box, you will get the error in a window. If you put the name of the function in the send to box, with send_to_script enabled, you will get the error on in the mud window, as it should happen | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #6 on Sun 23 Dec 2007 10:48 PM (UTC) |
Message
| Thanks for the detailed description. I have confirmed the error you describe. I had not passed down an optional argument to a C++ function, which resulted in it thinking there was no current world, and thus it had to display the dialog box.
Fixed in version 4.19. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | 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,464 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top