Mudlet Event Engine - Passing boolean values to raiseEvent

Is there a way, or at least some kind of work around that isn't horrendously convoluted, to pass a boolean variable as one of the arguments to raiseEvent? I'm currently using Mudlet 2.1, if that makes a difference (though I'm not sure I'd be willing to update just to fix this). Right now it just flat out doesn't work, and as far as I can tell it's not because I'm doing anything wrong - if I pass a different type of value, such as a string, then my function to handle the event does correctly receive the value as an argument.

Here's an example of what I've currently got:

function testEventHandler(event, name, defence, status)
    display(name)
    display(defence)
    display(status)
end

registerAnonymousEventHandler("test event", "testEventHandler")
If I then do raiseEvent("test event", "Antonius", "shield", true) I get "Antonius", "shield", and nil output from the event handler - it's not recognising that the value for "status" should be a boolean and is instead treating it as though no value was passed at all. If I change it to a string "true" then it gets passed fine, but then I can't use that as a boolean in event handlers; every single event handler would have to convert it back to a boolean themselves, which is ridiculous.

Comments

  • AustereAustere Tennessee
    If you send the string "true", you should still be able to run regular boolean checks on it.  Just don't send "false" when you need a false,  and it should all work the same, unless I am misunderstanding.
  • edited January 2016
    What if you passed a table to the event containing the values you want?

    Then read the expected values of the table.

    args = {
    thing = true,
    etc,
    etc
    }

    function testEventHandler(args)
  • Well, that's not horrendously convoluted, just horrendous... Might be the best option available though.
  • Antonius said:
    Well, that's not horrendously convoluted, just horrendous... Might be the best option available though.
    Yeah, that or write it in yourself, which at that point you might as well just bump to 3.
  • Not sure a table will work either. Looks like the function only accepts numbers or strings.
    https://github.com/Mudlet/Mudlet/blob/development/src/TLuaInterpreter.cpp#L295


    retired
  • well, that's disappointing.
  • You could do the old-fashioned C thing and just use 0 for false and 1 for true.

    Thought, 0 will still be seen as true by lua, unlike in C, so you'd have to do
    if x == 1 then
    instead of 
    if x then

    and do the same in any other conditional involving it.

  • You could see about patching the function to accept boolean values and submitting a pull request for it.
  • Amranu said:
    You could see about patching the function to accept boolean values and submitting a pull request for it.


    Maybe at a later date! I'll probably just work around it for now, and leave learning a new language for another time.

  • edited January 2016
    Just send "true" as a string. then do

    status = status == "true"

    at the start of the event handler. Or use 1. Whatever works.
    Current scripts: GoldTracker 1.2, mData 1.1
    Site: https://github.com/trevize-achaea/scripts/releases
    Thread: http://forums.achaea.com/discussion/4064/trevizes-scripts
    Latest update: 9/26/2015 better character name handling in GoldTracker, separation of script and settings, addition of gold report and gold distribute aliases.
  • I submitted a pull request with a quick fix to allow passing booleans (though no other types). Will update here if/when it's merged. Would still require updating, so it may or may not be ultimately helpful for you.
  • To add to Eld's comment and without looking at how to actually implement it, tables seem to be a lot less trivial to pass to events
  • This should be live in the next release (3.0.0-epsilon, I think?). In addition to booleans, you'll also be able to pass nil arguments without changing the length of the argument list. That is, currently, if you raiseEvent("eventname",arg1,nil,arg3), any handlers will be called as myHandler("eventname",arg1,arg3); in new versions, that will become myHandler("eventname",arg1,nil,arg3). raiseEvent() will also now throw a Lua error if it gets an argument with a type it doesn't recognize, such as tables or functions (which currently are treated the same as nil).
Sign In or Register to comment.