Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ General ➜ Accessing Global Objects from Within a Plugin

Accessing Global Objects from Within a Plugin

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


Posted by R-Strunk   (3 posts)  Bio
Date Wed 23 Feb 2022 02:12 AM (UTC)
Message
I suspect I'm way down the rabbit hole on this, but I'm hoping there's a simple solution.
I am using someone's basic script implementation that uses Bass instead of direct sound. This is because I use a screen reader, and I'm trying to play a lot of sounds at once. (It appears you can only play 10 with direct sound.) To this point, things have been working well, but as I create more triggers and aliases, I'm finding the control+shift+8 and control+shift+9 dialogs load a *lot* slower.
My thought, then, was to start exporting many of the sound triggers over to plugins, but that's where the breakdown is occurring.
At the outset of the script, the original author loads a class called "Interface" that contains lots of information about the player. It also has some callbacks and other functions I have built into it that enable me to play and manipulate sounds. At the moment, if I want to play a combat sound, I can do something like

Interface:CombatSound("windupstart")

to play the sound associated with the start of a windup.
If I do this from within a plugin, however, the Interface object isn't visible to the plugin.

Run-time error
Plugin: Detect_and_disrupt_windups (called from world: Starmourn)
Immediate execution
[string "Trigger: GetWinder"]:5: attempt to index field 'Interface' (a nil value)
stack traceback:
[string "Trigger: GetWinder"]:5: in main chunk

Is there a way for the plugin to be able to see (and call methods on) the global object? Failing that, is there a way for me to set up hundreds of triggers in such a way that loading the list doesn't completely freeze my computer?
Thanks for any help you can provide.
Top

Posted by Nick Gammon   Australia  (23,098 posts)  Bio   Forum Administrator
Date Reply #1 on Wed 23 Feb 2022 02:44 AM (UTC)
Message
How many triggers do you have? I made 5200 triggers using a script and there was only a slight delay opening the triggers configuration. It's a bit short to measure, but I estimate under a second. With 1000 triggers I didn't notice any loading time.

If you want to try that at home, here is the script:


for i = 1, 5000 do
  AddTrigger(string.format ("trigger%i", i), string.format ("Person %i says hello", i), 
     "hi there", 0, 0, 0, "", "")
end -- for


Paste that into the Immediate window to try it out (Ctrl+I). I would save the world first and then close it without saving afterwards, because you may find deleting 5000 triggers tedious.

I think the simple solution in your case is to make the triggers send some string to "Execute" rather than playing the sounds themselves. Then in the main world make an alias that picks up this string and plays the sound. This is a common way of sending data from one script space to another.

For example, in the trigger in the plugin, do this:


 Execute ("Play sound: dog barking")


In your main world file have an alias like this:


Match: Play sound: *


Then that alias works out what file to play from the wildcard. If your triggers mentioned a file name, then just put the file name as the thing in the Execute function call.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by R-Strunk   (3 posts)  Bio
Date Reply #2 on Wed 23 Feb 2022 03:09 AM (UTC)
Message
For what it's worth, I created the 5000 triggers you suggested, and I hit all kinds of lag. I'm on a 6-year-old HP Specter, which should be fast enough, though it's possible my screen reader is also the culprit. In either case, the end result was that it took approximately 15 seconds for the window to load such that the "not responding" message went away, and arrowing through the list took around 7 seconds to move from one item to the next.
I'll give your alias wrapper a shot. Thanks for your help.
Top

Posted by Nick Gammon   Australia  (23,098 posts)  Bio   Forum Administrator
Date Reply #3 on Wed 23 Feb 2022 04:22 AM (UTC)
Message
Quite possibly the screen reader adds extra overhead.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


7,620 views.

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

Go to topic:           Search the forum


[Go to top] top

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