Overriding variable in my plugin

Posted by Gore on Mon 05 Dec 2005 08:58 PM — 7 posts, 31,853 views.

#0
After I split up my plugin into 20 different files or so, I kept getting this error message

Line 218: overwriting existing variable contents (var_pipe_elm)


when trying to load that variable from the state file, after I set the variable while it's loaded. Any ideas?
Australia Forum Administrator #1
You must have it declared in more than one place. For example, once in the plugin and once in the state file.
#2
I tried deleting the state file to see if that would solve the problem but it didn't.
Australia Forum Administrator #3
You need to delete the variable from the plugin file. This plugin will reproduce the problem:


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Tuesday, December 06, 2005, 11:15 AM -->
<!-- MuClient version 3.71 -->

<!-- Plugin "variabletest" generated by Plugin Wizard -->

<muclient>
<plugin
   name="variabletest"
   author="Nick Gammon"
   id="d2be8865570f7729bd130584"
   language="Lua"
   purpose="tests a problem Gore has"
   save_state="y"
   date_written="2005-12-06 11:14:46"
   requires="3.60"
   version="1.0"
   >

</plugin>

<!--  Aliases -->

<aliases>
  <alias
   match="target *"
   enabled="y"
   variable="victim"
   send_to="9"
   sequence="100"
  >
  <send>%1</send>
  </alias>
</aliases>


<!--  Variables  -->

<variables>
  <variable name="victim">Gore</variable>
</variables>

</muclient>


Note how variable "victim" is declared in the plugin itself as Gore? Now if the plugin changes that, in this case you could do it by typing "target Nick", then it now has "Gore" in the plugin file, and "Nick" in the state file. Then you get the warning about overwriting a variable.

Basically variables that might change should not be declared in the main plugin file.
Amended on Mon 05 Dec 2005 11:35 PM by Nick Gammon
#4
So basically, any variable I might change I would manually put into the state file or? Do I just Setvariable "whatever", "whatever" without any sort of declared variable, and would it automaticly make it in the state file?
USA #5
As long as the plugin itself has the save_state field set to "y", then any use of setvariable will automatically save that value into the state file when it happens. Same with setting a variable through aliases, etc.
Australia Forum Administrator #6
How would you manually put it into the state file?

Shadowfyr is right, simply set the variable, all variables in the plugin are saved to the state file. That is, all variables that exist at save time, not just the ones declared in the plugin file.