AcceleratorTo(key, "scriptfunc()", 12) executes in world

Posted by Worstje on Sat 26 Sep 2009 05:13 PM — 9 posts, 32,264 views.

Netherlands #0
AcceleratorTo while using the Send To Script (12) option ends up executing the script in the world environment, rather than the environment of the plugin that registered the accelerator. I perceive this to be a bug, given the design of MUSHclient in other similar areas:

- Timers added using this option execute in the plugin.
- Triggers added using this option execute in the plugin.
- Aliases added using this option execute in the plugin.

The reason, as I understand, for the above functions to run in their own plugin is because plugins are not supposed to be able to interfere with the main world, at least not on a script level (hell, you can't even know if the main world is using Lua or VBScript, so it would never be reliable either).

Test case:

--Put this in a plugin:
AcceleratorTo ("Numpad0", "test_func()", 12)

function test_func()
  Note("Plugin got called.")
end


And execute this in your world (assuming Lua):

function test_func()
  Note("MAIN WORLD got called. This is bad!")
end


Guess which one shows up when you hit the Numpad0 button? :)
USA #1
Gack! You know, I was just going to post about this, but I got ninja'd. :( My novice opinion is that it's not saving the context of the accelerator (the plugin/world ID or whatnot), so it's calling to the world. Maybe if the accelerators used the same (or similar) mechanism as the OnPlugin* callbacks?
Netherlands #2
I think the trigger/timer/aliases (or TTA's for short from here on forth) are better comparisons than the OnPlugin* callbacks, which are a different beast. After all, those are a simple matter of testing the script for a function and executing it, whereas the sendto.script method is a wholly other beast.

TTA's support everything scriptingwise. You can assign variables etc, it is not limited to a specific function.

Since you'd want AcceleratorTo(key, "keypressed = true", 12) to work as well for whatever reason (people will find one, trust me), it can't be a callFunction() kind of execution, but has to be a executeScript() kind of method to invoke the script.

Here's an example. Suppose you use the keypad for various affairs. Do you want to make seperate functions to handle each key? Eg... (assuming a script function callback):

AcceleratorTo("Numpad0", "KeyPressNumpadZero", 12);
AcceleratorTo("Numpad1", "KeyPressNumpadOne", 12);
AcceleratorTo("Numpad2", "KeyPressNumpadTwo", 12);
AcceleratorTo("Numpad3", "KeyPressNumpadThree", 12);
...


That would be troublesome. All you can do is call functions. Better would be, with it working as a script like right now:

AcceleratorTo("Numpad0", "KeyPress(0)", 12);
AcceleratorTo("Numpad1", "KeyPress(1)", 12);
AcceleratorTo("Numpad2", "KeyPress(2)", 12);
AcceleratorTo("Numpad3", "KeyPress(3)", 12);
...


That way you can re-use the same function.

To explain in another way... TTA's have 'send to script'. That executes code. TTA's also have a Script field. Which is like the callback you suggest. The latter is a lot more limited, and since Accelerators() aren't exactly full objects like TTA's are, you will want the flexibility. Right now, it is already implemented as a 'send to script', which is good, so that should definitely not change. Callbacks would simply end up as an inconsistency with the rest of similar functions.

USA #3
Point taken! All a fix would really have to do to run that accelerator, as far as I know, is store the world/plugin ID where it occurred and use that one's script engine to run the script, then.
Australia Forum Administrator #4
Point taken. When accelerators just did an Execute it didn't matter. I'll have to store the plugin ID with each accelerator.
USA Global Moderator #5
Did you decide to not fix this? I suppose it's not the end of the world to use CallPlugin.
Australia Forum Administrator #6
I must have forgotten about it.

Would you think that (say) send-to-variable would then send to a plugin's variable rather than the main world file's variable?
Australia Forum Administrator #7
Actually send-to-variable doesn't work in accelerators anyway.
Australia Forum Administrator #8
Suggestion implemented in version 4.76.