Evaluating client variables in script

Posted by Cosine_Omerta on Fri 02 Jan 2015 01:07 AM — 8 posts, 28,769 views.

USA #0
I've been scouring the forum for a few hours, I've watched a few videos, and I can't find a solution to what I'm sure is a simple problem. I'm sorry if this is the 300th time it's been posted.

I have created a miniwindow, with a rectangle, with a hotspot mapped to that rectangle, with a simple mouseup function that sends some text to the mud. I want a client variable to be evaluated against a condition, and depending on that send various text to the mud.

Everything seems to be fine, but I cannot get the conditional statement to evaluate to anything but false.

I have a variable on the client called char_name, which is set via trigger. This works fine. I click on the variables button on the client, it says "char_name Bob", no problems there.

When I try to evaluate this in my script (which is in an xml file and added via plugins) its always false. This is the exact format I've been using in the client, and it evaluates properly there. I'm sure I'm missing some little something.


if (GetVariable("char_name") == "Bob") then
 name = "Bob"
else
 name = "Dick"
end

function mouseup (flags, hs1)
  print(name)
end --mouseup


It always prints "Dick" even though the variable is set to "Bob".
Australia Forum Administrator #1
Variables in plug-ins and the main world are in different spaces.

Template:function=GetPluginVariable
GetPluginVariable

The documentation for the GetPluginVariable script function is available online. It is also in the MUSHclient help file.

USA #2
Thank you.

How do you go back the other way? Use a call in the script to set a client variable? I don't see a SetPluginVariable type function. SetVariable doesn't work.
USA #3
Maybe a different question then. When one wants to share variables between scripts and the client (to have triggers and aliases in the client, and outside scripts or plugins all using the same variable), what is the preferred method?
Australia Forum Administrator #4
Cosine_Omerta said:

Thank you.

How do you go back the other way? Use a call in the script to set a client variable? I don't see a SetPluginVariable type function. SetVariable doesn't work.


Plugins are intended to be independent of each other and the main script file. Having plugins set each others variables does not work with that design concept. So there is no SetPluginVariable function, by design.

However you can work around this by having a plugin "Execute" some thing which an alias in the main world file picks up and changes a variable. I think someone else came up with a more sophisticated method a while back as well, can't remember what it was.
USA #5
Surely people do this though. Do they just keep any associated variables/triggers/aliases in the plugin file? Then just use multiple aliases that do the same thing for different plugins?
Australia Forum Administrator #6
I seem to have answered your original question. Is this new question (setting variables rather than reading them) mere curiosity, or do you have an application in mind?

If so, what is it?

http://xyproblem.info/
Amended on Wed 07 Jan 2015 05:34 AM by Nick Gammon
USA #7
Sorry. Just new to mushclient and trying to figure it out. Didn't mean to be a pest.