[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]  Lua
. . -> [Subject]  Sharing Lua data between plugins and global spaces
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Sharing Lua data between plugins and global spaces

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


Posted by Larkin   (278 posts)  [Biography] bio
Date Wed 09 Mar 2005 06:51 PM (UTC)
Message
I'm trying to find a way (pretty much any way) to share data between plugins and/or the global space. I had thought that a sensible workaround might be to store things in MUSHclient variables and then get the data from there, but it doesn't seem to retrieve the variables correctly in my plugin.

I made an alias that calls some Lua code to process parameters and store the results in a MUSHclient variable. This alias is in the global space. Then, in my plugin I have a different alias that first checks the value of the MUSHclient variable before deciding whether or not to act. When I get the value in the plugin, however, it's always nil. Looking at the variables dialog shows that the variable exists and has the value "true" in it.

Any ideas?
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Reply #1 on Wed 09 Mar 2005 07:00 PM (UTC)
Message
Are you using GetPluginVariable to get the Mushclient variable with the plugin?

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by Larkin   (278 posts)  [Biography] bio
Date Reply #2 on Wed 09 Mar 2005 07:32 PM (UTC)
Message
Nope. I'm actually using the Lua variables table script from Nick to access them.
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Reply #3 on Wed 09 Mar 2005 07:49 PM (UTC)

Amended on Wed 09 Mar 2005 07:55 PM (UTC) by Flannel

Message
You'll either have to use GetPluginVariable directly (for that specific variable), or implement a second metatable (that uses [Get|Set]PluginVariable, since thats all the table script does, is save typing by linking get/setvariable to the tables metamethod) and obviously name it something other than var (global or whatnot) to access it.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by Larkin   (278 posts)  [Biography] bio
Date Reply #4 on Wed 09 Mar 2005 08:02 PM (UTC)
Message
I did a sort of hack to workaround this, and I'm not sure if I should just go with this method or not. What I did was modify the the script from Nick to basically search a path for a specified variable name. It starts with the most often used plugin and then defaults to the world variable at the end.

Here's the modified indexer function:
 -- called to access an entry
 __index = 
 function (t, name) 
  local result
  -- Check the tracking plugin first
  result = GetPluginVariable ("7418e3f130e83fde1d68a401", name)
  -- If the result is still nil, check the global space
  if result == nil then
    result = GetVariable(name)
  end
  return result
 end;
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Reply #5 on Wed 09 Mar 2005 08:45 PM (UTC)

Amended on Wed 09 Mar 2005 08:48 PM (UTC) by Flannel

Message
If youre getting a world variable from a plugin (which is what you said you were trying to do) you'll still need to use GetPluginVariable (with a null PID) since your GetVariable calls will find the (local) plugin variable, not the global one.
So if you'd like, you could use the PIDs and dynamically cycle through them (based on context) (including null for global where appropriate) and find the variable (and therefore you wouldn't need to store them intermediately in the world. Assuming you knew which plugin you wanted (for same variable names)).

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by Larkin   (278 posts)  [Biography] bio
Date Reply #6 on Thu 10 Mar 2005 01:36 PM (UTC)
Message
The reason I did the workaround and added the call to GetPluginVariable while keeping the GetVariable call is because the variables I had set in the plugin didn't go to the world and there was no way that I could see to make them go to the world, other than to have a global alias that set them there.

I designed the system to have a global alias to track afflictions or defenses and then the realm-specific tracking plugin would have certain override aliases for handling any special cases. If the plugin aliases try to set variables, they don't go in the same place, so I have to pass any values on to the global aliases.

I also didn't realize that I could use a nil plugin ID to get a world variable from anywhere. I think I may try that in this design to see how I like it. Thanks for the tip!
[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.


4,945 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]