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
➜ Lua
➜ Avoiding errors with nil values AND disabling timers fast
Avoiding errors with nil values AND disabling timers fast
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Silencher
(55 posts) Bio
|
Date
| Fri 10 Apr 2015 01:21 PM (UTC) |
Message
| Is there a way to avoid error message pop ups for nil values in Hard variables? Example: an if statement that calls GetVariable but the target variable doesn't exist.
Also- short of manually clicking disable and disconnecting from a mud, is there a way to disable all timers? I have a timer on a 1 second loop and it's active when disconnected and it is screwing me up everytime i load that world because it has an error in it and is giving me continuous pop up errors. not sure how to fix it. Is there any quick shortcut to disable all timers? | Top |
|
Posted by
| Fiendish
USA (2,536 posts) Bio
Global Moderator |
Date
| Reply #1 on Fri 10 Apr 2015 03:23 PM (UTC) Amended on Fri 10 Apr 2015 03:29 PM (UTC) by Fiendish
|
Message
|
Quote: Is there a way to avoid error message pop ups for nil values in Hard variables? Example: an if statement that calls GetVariable but the target variable doesn't exist. The documentation for GetVariable says it just returns nil. So why not check if the result is nil before trying to use it?
I'm pretty sure that timer control is per-world. You could go and edit your world file.
Or use http://www.gammon.com.au/scripts/doc.php?function=EnableTimer
or maybe SetOption("enable_timers", 0) |
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Silencher
(55 posts) Bio
|
Date
| Reply #2 on Fri 10 Apr 2015 04:13 PM (UTC) |
Message
| Sorry, can you show me an example of how to check for a nil value? i realize this is likely a 'newb' question but i have no idea | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #3 on Fri 10 Apr 2015 07:54 PM (UTC) Amended on Fri 10 Apr 2015 07:55 PM (UTC) by Nick Gammon
|
Message
| You could use two methods. One is:
foo = GetVariable ("foo")
if foo then
-- do something with it
end -- if
In Lua doing an "if variable" is equivalent to checking if it is nil or not (and also if it is false or not but that wouldn't apply in this case).
More explicitly:
foo = GetVariable ("foo")
if foo ~= nil then
-- do something with it
end -- if
Another technique which is often used is to force in a default value, eg.
foo = GetVariable ("foo") or ""
-- use foo
This uses "short-circuit" evaluation. Either you get the variable foo, or if that doesn't exist you get a "default" of an empty string (which won't be nil). You could make the default something else if you wanted (eg. zero). |
- 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.
15,655 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top