[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]  Plugins
. . -> [Subject]  Plugins using variables
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Plugins using variables

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


Posted by Korishan   USA  (5 posts)  [Biography] bio
Date Mon 20 Jan 2003 01:58 AM (UTC)
Message
I've tried to do a world.setvariable on a plugin I'm writing. It's for setting up prompts in the infobar. I'm making it configurable by the user on how they have thier prompt set up so that anyone can use it w/o having to reset thier prompt to a pre-specified one. So, upon installation of the plugin, it asks a series of questions. This first on, of course, would be what is the layout of your prompt.
I get the input using an inputbox. Store it into a variable called Temp. Then I do a world.setvariable "InfoPrompt", Temp
I go into variables and check to see if it's changed it, and it hasn't. I also did on the next line, world.note world.getvariable ("InfoPrompt"), and it displays the input that I put in.
Now, what do I believe. did the variable of the world get updated, or did the internal variable of the plugin get updated and as soon as I close the client down, the variable is trashed?

Korishan, aka Rheede
[Go to top] top

Posted by Magnum   Canada  (580 posts)  [Biography] bio
Date Reply #1 on Mon 20 Jan 2003 04:50 AM (UTC)
Message
Believe the note.

The variable list GUI does NOT display Plugin data.

You can also use: /world.debug "plugins"

That will output to your screen all the data MUSHclient holds pertaining to your plugins.

(Remember, a variable set in a plugin belongs ONLY to that plugin. You need to use a special function to access the variable from outside the plugin: World.GetPluginVariable).

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
[Go to top] top

Posted by Korishan   USA  (5 posts)  [Biography] bio
Date Reply #2 on Mon 20 Jan 2003 04:54 AM (UTC)
Message
Ahhh, ok, gotcha. Ok, then how do u save data from session to session with a plugin? Like with my InfoPrompt plugin, it stores how many trains you've gained and keeps a tally of them. How do I store that over a close of the program? Or, another feature I have, is that it keeps track of a particular skill and monitors it's increase in percentage. How can I keep track of that skill percent without having to re-execute the command to turn on skill monitoring everytime I reload my program?
With your example of World.GetPluginVariable, is there a way to store plugin variables inside the world variables???

Korishan
[Go to top] top

Posted by Magnum   Canada  (580 posts)  [Biography] bio
Date Reply #3 on Mon 20 Jan 2003 03:38 PM (UTC)
Message
Any MUSHclient variables you use within your plugin will be stored in a state file. (Within a "state" directory which is a subdirectory of your "plugins" directory.)

So, for example, if you World.SetVariable "Target", "Green Orc", Then that value will still exist the next time you load the plugin.

There is one special rule about this:

<plugin
	name=""
	date_written = "2003-01-20"
	date_modified = "2003-01-20"
	version="1.0"
	requires="3.25"
	author="Magnum"
	id=""									<!-- /world.note world.getuniqueid -->
	purpose=""
	language="VBscript"
	save_state="y"
	>

<description trim="y">
<![CDATA[
This is a Magnum's Default plugin. This line should be changed.
]]>
</description>
</plugin>

That last directive, save_state="y" must be present, or your plugin will NOT save values in between sessions.

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #4 on Fri 18 Jun 2004 02:15 PM (UTC)
Message
Sorry, for reviving a thread more than a year old, but it came up on a search and looks relevant. Seems like one of my plugins (AutoHealer to be specific) doesn't read the saved state. I checked the corresponding file in the State folder, it exists and contains what it should, but closing and opening the world where the plugin is installed results in the default value being loaded instead of a saved one. I checked with 3.49 and 3.50. Any idea why that is?
[Go to top] top

Posted by Nick Gammon   Australia  (21,388 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Fri 18 Jun 2004 10:30 PM (UTC)
Message
Does closing and opening the plugin (not the world) keep the state?

Does the plugin change that variable itself?

Maybe it reloads the state and then initialises the variable to be empty.

Perhaps put some debugging in OnPluginInstall to see if the variable was in fact loaded OK.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #6 on Sat 19 Jun 2004 03:35 AM (UTC)
Message
1. Not sure what you mean by opening and closing the plugin. Adding/Removing it from the list overwrites the variable, but that's how it always worked.

2. To test I use an alias that notes the current value and then changes it with world.SetVariable. Then I close the world, open it up again, and use the alias to check whether the value was retained.

3. Nope, the variable has a default value.

4. OnPluginInstall isn't called when the plugin is being loaded, only when the plugin is installed/reinstalled, so it doesn't seem to help much.

The state file contains the value that I set using the alias in point 2, it just looks like the state file is never used when opening the plugin for some reason.
[Go to top] top

Posted by Nick Gammon   Australia  (21,388 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Sat 19 Jun 2004 05:33 AM (UTC)
Message


  1. I mean to add/remove it from the plugin list. That opens/closes the plugin.

  2. Is this alias in the plugin or the main world?

  3. Er, well the plugin must change the variable at some point, otherwise there is no point to having it.

  4. The "OnPluginInstall" routine is called when the plugin is installed, that is, loaded. So it will be called every time you add it to the plugin list, or open the world file.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #8 on Sat 19 Jun 2004 07:21 AM (UTC)
Message
1. Yes, I tried adding/removing but it gives the "overwritting existing variable" message and promptly overwrites it with the default value.

2. The alias is in the same plugin with with the variable.

3. It does change the value, the alias above for instance calls this script:


sub Test(a,b,c)
  world.Note world.GetVariable("MaxHealth")
  world.Execute "AutoHealer:maxHealth 80"
end sub


4. Yep, seems like it does. I thought it doesn't since every time I tried testing OnPluginInstall, I used a world.Note and those don't seem to be displayed until the world is opened, which in turn seems to happen only after all plugins are loaded. But Adding/Removing the plugin shows the world.Note. However, it also overwrites the variable, as I already said.
[Go to top] top

Posted by Shadowfyr   USA  (1,783 posts)  [Biography] bio
Date Reply #9 on Sat 19 Jun 2004 09:05 PM (UTC)
Message
When the client initially starts up the output buffer isn't immediately available, so a note in the OnPluginInstall will only apear if a) delayed or b) the client is already open. Generally, in my plugins I always test some variable to see if its value is set, then 'only' set the default if it doesn't already exist.
[Go to top] top

Posted by Nick Gammon   Australia  (21,388 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Sat 19 Jun 2004 11:11 PM (UTC)
Message
Quote:

Yes, I tried adding/removing but it gives the "overwritting existing variable" message and promptly overwrites it with the default value.


What message is that? You shouldn't get that message when you remove and re-add a plugin. That message pertains to closing the world file, and is for variables in the main file.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #11 on Sun 20 Jun 2004 09:15 PM (UTC)
Message
Here's step by step what I do:

1. Open world with the plugin and type "test"
2. Alias "test" does a world.Note with the current value of the MaxHealth variable and then sets that value to 80, noting the new value. That displays:


56
AutoHealer plugin: you've set your max health to 80


with 56 being the default value for the variable:

3. File->Plugins. Select AutoHealer from the list, click on Remove. Click on Add and install the plugin again. The "XML import warnings" window comes up with:

Line  161: overwriting existing variable contents (maxhealth)


4. OnPluginInstalled handler does a world.Note with "installed " & world.GetVariable("MaxHealth"), the result being again:

installed 56


The same thing (with the plugin overwriting the saved value with the default one) happens when opening/closing the world also. Here's the contents of the plugin's state file for that world:


<!-- Saved on Monday, June 21, 2004, 8:07 AM -->
<!-- MuClient version 3.49 -->
<!-- Written by Nick Gammon <nick@gammon.com.au> -->
<!-- Home Page: http://www.muclient.com/ -->
-
	<!--
 Plugin state saved. Plugin: "AutoHealer". World: "imperian". 
-->
-
	<muclient>
<!-- variables -->
-
	<variables muclient_version="3.49" world_file_version="15" date_saved="2004-06-21 08:07:18">
<variable name="Gauge">1</variable>
<variable name="HealthFloor">85</variable>
<variable name="ManaFloor">85</variable>
<variable name="MaxHealth">80</variable>
<variable name="MaxMana">52</variable>
<variable name="MossFloor">65</variable>
</variables>
</muclient>


As you can see, the "MaxHealth" here has a value of 80, which is what I set it to with the "test" alias. So my guess is that the state file is somehow skipped or the values loaded from it are overwritten at some point in loading the plugin?
[Go to top] top

Posted by Nick Gammon   Australia  (21,388 posts)  [Biography] bio   Forum Administrator
Date Reply #12 on Sun 20 Jun 2004 10:23 PM (UTC)

Amended on Sun 20 Jun 2004 10:24 PM (UTC) by Nick Gammon

Message
Quote:

Line 161: overwriting existing variable contents (maxhealth)


I am guessing that in line 161 of your plugin (not your state file) you have that variable defined.

What is happening here is that:


  1. The plugin is loaded. The first thing it does is get the:


    • Name
    • Author
    • Language
    • ID
    • Purpose
    • Date written
    • Date modified
    • Save_state flag
    • Requires "version of MUSHclient" field
    • Version number


  2. Then it checks various things (name not blank, version OK, purpose not too long etc.)

  3. Then it loads the state file.

  4. Then it loads the rest of the things, triggers, aliases, timers, variables, etc.


Note the sequence here. The variable in the plugin overwrites the variable in the state file.

Hence the warning message. What you need to do is remove the variable line from the plugin. Then your problem will go away.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #13 on Sun 20 Jun 2004 10:33 PM (UTC)
Message
Aha, worked! Though I would've never guessed that myself.
[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.


7,776 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]