wait.lua error messages

Posted by Fiendish on Sun 30 Sep 2012 05:46 AM — 5 posts, 15,981 views.

USA Global Moderator #0
Because assertion errors are big and scary (and don't direct the uneducated user to a solution), I'm considering doing the following in my distribution of wait.lua:

 function make (f)
   assert (type (f) == "function", "wait.make requires a function")
-  assert (GetOption ("enable_timers") == 1, "Timers not enabled")
-  assert (GetOption ("enable_triggers") == 1, "Triggers not enabled")
+  local errors = {}
+  if GetOption("enable_timers") ~= 1 then
+    table.insert(errors, "TIMERS")
+  end
+  if GetOption("enable_triggers") ~= 1 then
+    table.insert(errors, "TRIGGERS")
+  end
+  if #errors ~= 0 then
+    ColourNote("white","red","One of your scripts (in '"..(GetPluginInfo(GetPluginID(), 1) or "World").."') just did something that requires "..table.concat(errors, " and ").." to be enabled, but they aren't. Please check your configuration settings.")
+    return -1
+  end
   coroutine.wrap (f) () -- make coroutine, resume it
+  return 0
 end -- make

What do you think?
Amended on Sun 30 Sep 2012 06:39 AM by Fiendish
Australia Forum Administrator #1
What is the return for? For checking somewhere else?
Australia Forum Administrator #2
How about returning nil on an error and true on OK, like other similar functions?
USA Global Moderator #3
Nick Gammon said:

What is the return for? For checking somewhere else?
Yes.

Nick Gammon said:

How about returning nil on an error and true on OK, like other similar functions?
That would also work.
Australia Forum Administrator #4
I like it. Incorporated in version 4.84 along with a few other fixes. Bad return will be nil, good return will be true.