I have a plugin which depends on two world (MC) variables to function properly. The values of these two variables are set by VBS subprocedures in the main script file. The plugin appears to work fine except for the fact that it cannot access those variables. I was wondering if this is the way it's supposed to work, and if it is then is there any way to access world variables which are not directly included in the plugin itself?
I may be doing something wrong here, since allowing scripts in plugins to share the same variables in the world file would seem to be the most obvious way to go. But at the same time the other 3 world variables, which are set from inside the plugin seem to work just fine. Which brings up another question: can 'plugin' world variables be accessed from another plugin or the main script (or from triggers and aliases set up in GUI)?
Although including the chunk of script which is responsible for setting the variables' values in the plugin isn't that much of a problem, this unexpected error made me curious about how plugins communicate with the world file and other plugins. Maybe someone could provide guidance or pointers to existing posts on the matter.
Thanks in advance.
Plugins are intended to be self contained. In some respects they break this rule by accessing global world options, but in general communication between plugins or the main script is possible only with a little work.
However.. You should be able to do this:
dim Linkworld
set Linkworld = getworld("Your worlds name")
if Linkworld <> nothing then
Linkworld.getvariable ...
Linkworld.setvariable ...
etc.
end if
See GetPluginVariable - this lets you get variables from other plugins, and global variables as well.
Thanks, Nick. I've found the world.getpluginvariable in the callbacks list shortly after posting :) But I'll be using the Linkworld trick you've provided very often.
I see your point in making plugins little 'worlds' of their own, but my problem is that I have many things in my main script that are tied together by the use of same world variables, yet are intended for different functional purposes which places them in different plugins. So being able to retrieve variables from the world file makes more sense if I want to make the script distributable in parts, rather than giving out the entire thing.
Thank you again.
Erm, and here comes another correction... I saw Nick's name on the recent posts which got me convinced that the first reply was also his. Thanks Shadowfyr and Nick! :P