[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Bug reports
. . -> [Subject]  AcceleratorTo(key, "scriptfunc()", 12) executes in world
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

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

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Sat 26 Sep 2009 05:13 PM (UTC)
Message
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? :)
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #1 on Sat 26 Sep 2009 07:08 PM (UTC)
Message
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?

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #2 on Sat 26 Sep 2009 08:23 PM (UTC)
Message
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.

[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #3 on Sat 26 Sep 2009 09:37 PM (UTC)
Message
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.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Sat 26 Sep 2009 11:09 PM (UTC)
Message
Point taken. When accelerators just did an Execute it didn't matter. I'll have to store the plugin ID with each accelerator.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Fiendish   USA  (1,641 posts)  [Biography] bio   Global Moderator
Date Reply #5 on Thu 16 Jun 2011 08:29 AM (UTC)
Message
Did you decide to not fix this? I suppose it's not the end of the world to use CallPlugin.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Thu 16 Jun 2011 10:59 PM (UTC)
Message
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?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Thu 16 Jun 2011 11:12 PM (UTC)
Message
Actually send-to-variable doesn't work in accelerators anyway.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Thu 16 Jun 2011 11:27 PM (UTC)
Message
Suggestion implemented in version 4.76.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] 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.


6,346 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]