Accessing Global Objects from Within a Plugin

Posted by R-Strunk on Wed 23 Feb 2022 02:12 AM — 4 posts, 12,347 views.

#0
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.
Australia Forum Administrator #1
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.
#2
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.
Australia Forum Administrator #3
Quite possibly the screen reader adds extra overhead.