Mudlet 3.6 setLabelClickCallback Error with raiseEvent
Mudlet 3.6 setLabelClickCallback Error with raiseEvent
With the changes to how setLabelClickCallback (and related functions) work in Mudlet 3.6, in which they pass a table as a final argument with some additional data about the mouse position and such, every instance in which I had the callback use the raiseEvent function now generates an error, because a table is not a valid argument for the raiseEvent function. How can this be remedied aside from writing my own event handling system?
- SlySven
- Posts: 1023
- Joined: Mon Mar 04, 2013 3:40 pm
- Location: Deepest Wiltshire, UK
- Discord: SlySven#2703
Re: Mudlet 3.6 setLabelClickCallback Error with raiseEvent
By metaphysically kicking us developers who failed to spot this issue...
Raising Issue 1466 to track this.
Raising Issue 1466 to track this.
Re: Mudlet 3.6 setLabelClickCallback Error with raiseEvent
Could you explain what you're doing a bit more - are you passing the arguments back onto raiseEvent()?
Re: Mudlet 3.6 setLabelClickCallback Error with raiseEvent
I am simply trying to raise an event when a label is clicked. In general, some strings are also passed as arguments, so as to identify which label got clicked, but certainly nothing complicated as far as events go. Here is one example of where this is being used: setLabelClickCallback("scan_tab","raiseEvent","onDisplay","scan")
In this case, I have a number of labels along the top of an area which can display different sets of information. Click the appropriate tab, and that info is revealed. The code has not changed in any way for quite some time, but as of the 3.6 release, it no longer functions, because setLabelClickCallback now passes, on its own, an additional argument to the function it is used to call, and that argument is a table, which is not supported by raiseEvent. As for why I chose to use events rather than a function call, using an event makes it very easy to just drop in additional scripts into the setup, without requiring any changes to existing code. Each script knows to hide or show its content if the onDisplay event is called, based on if that script is identified by the accompanying argument. As I mentioned in the initial post, obviously I could do something similar by creating essentially my own event handling system, but that seems like overkill (not to mention a lot of work), just to get things working again.
Edit: Based on my understanding, even if I didn't try to pass any arguments to raiseEvent (other than the event name itself), the same problem would occur. So, setLabelClickCallback can no longer be used with raiseEvent, regardless of what you wanted to do with it.
In this case, I have a number of labels along the top of an area which can display different sets of information. Click the appropriate tab, and that info is revealed. The code has not changed in any way for quite some time, but as of the 3.6 release, it no longer functions, because setLabelClickCallback now passes, on its own, an additional argument to the function it is used to call, and that argument is a table, which is not supported by raiseEvent. As for why I chose to use events rather than a function call, using an event makes it very easy to just drop in additional scripts into the setup, without requiring any changes to existing code. Each script knows to hide or show its content if the onDisplay event is called, based on if that script is identified by the accompanying argument. As I mentioned in the initial post, obviously I could do something similar by creating essentially my own event handling system, but that seems like overkill (not to mention a lot of work), just to get things working again.
Edit: Based on my understanding, even if I didn't try to pass any arguments to raiseEvent (other than the event name itself), the same problem would occur. So, setLabelClickCallback can no longer be used with raiseEvent, regardless of what you wanted to do with it.
Re: Mudlet 3.6 setLabelClickCallback Error with raiseEvent
Yes, that's right, we didn't think of that usecase. So the options are: either enable event system to pass tables (efficiently...) or don't use a table for all of the additional arguments, but that would not be nice as there is a lot of them.
Re: Mudlet 3.6 setLabelClickCallback Error with raiseEvent
Alternately, you could have a final (optional) argument that determines if the new table is passed to the called function or not. Like this: setLabelClickCallback(“my label”,”func”,”arg”,true)
That way, all previous uses of setLabelClickCallback, which obviously weren’t using the new info, won’t be receiving it. And new uses can choose if they want that extra info passed to them or not.
That way, you avoid having to change events to handle tables, and you avoid having to pass a ton of extra arguments individually. Granted, code created since 3.6 was released would need to be adjusted, if they needed the extra info being passed, but it hasn’t been around that long, so hopefully that is a less burdensome task.
Edit: Or, since someone could be passing a Boolean as an argument to their function with setLabelClickCallback, but the function to be called has to always be the second argument, and must be a string, you could put the optional argument there, like this: setLabelClickCallback(“my label”, true, “func”, arg)
That way, all previous uses of setLabelClickCallback, which obviously weren’t using the new info, won’t be receiving it. And new uses can choose if they want that extra info passed to them or not.
That way, you avoid having to change events to handle tables, and you avoid having to pass a ton of extra arguments individually. Granted, code created since 3.6 was released would need to be adjusted, if they needed the extra info being passed, but it hasn’t been around that long, so hopefully that is a less burdensome task.
Edit: Or, since someone could be passing a Boolean as an argument to their function with setLabelClickCallback, but the function to be called has to always be the second argument, and must be a string, you could put the optional argument there, like this: setLabelClickCallback(“my label”, true, “func”, arg)
Re: Mudlet 3.6 setLabelClickCallback Error with raiseEvent
Jacen went ahead and added table support: https://github.com/Mudlet/Mudlet/pull/1472
Re: Mudlet 3.6 setLabelClickCallback Error with raiseEvent
@Jor'Mix: you can test a build with https://transfer.sh/g2tAs/Mudlet-3.6.1- ... c5ef66.dmg. Worked OK in my testing and you can even pass functions now. Not sure if that's useful for your usecase, but it does mean you can pass a complete Geyser object and it'll still work. We've implemented it efficiently so there's no copies being made, just a reference, so it is still super fast.
Re: Mudlet 3.6 setLabelClickCallback Error with raiseEvent
Fixed with https://www.mudlet.org/2017/12/mudlet-3 ... be-deleted. Thanks for reporting it promptly!