Possible SetVariable/DeleteVariable bug

Posted by Poromenos on Mon 24 May 2004 10:47 AM — 5 posts, 18,780 views.

Greece #0
It has been a long time since I did this, and it could be my fault, but I thought I'd tell you to check it out in case it was a bug, can't hurt anyway :)
A few weeks ago I was making a plugin to store an array in variables. What I did was this:

Dim intCounter
For intCounter = 1 to 10
    DeleteVariable "World_Variable_" & intCounter
Next
SetVariable "World_Variable_1", "stuff"


The state file had 3 variables in it, "World_Variable_1" to 3. The script deleted them and added the variable 1, but they weren't deleted from the state file. No matter how many times I ran it, it always had 3 variables in it. I even did World.Note to see if they were deleted, and it clearly showed that it deleted the 3 variables and inserted the other one, but when I ran it again, it still deleted 3 variables. I just deleted the state file and it runs fine now, but it struck me as odd... Maybe Nick could look into it?
Australia Forum Administrator #1
I can't reproduce that. You need to save the state file (eg. remove the plugin) first, the state file is not saved moment-by-moment.

However my test plugin works - once the variables are deleted, and the plugin closed and re-opened, the variables are gone.
Greece #2
This script was run on OnPluginInstall, and I was reloading the plugin... Reloading saves the variables, doesn't it?
Australia Forum Administrator #3
Reloading should save the variables, yes.

Are the variables also in the plugin itself? Not that it should matter. Are you sure the OnPluginInstall script runs?

Try putting in a note, like I did:


sub OnPluginInstall
Dim intCounter
Note "in OnPluginInstall"

For intCounter = 1 to 10
    Note "delete = " & DeleteVariable ("World_Variable_" & intCounter)
Next
SetVariable "World_Variable_1", "stuff"
end sub


That confirms that the script ran, and shows the results of the deletion. You should see either of these cases:


in OnPluginInstall
delete = 0
delete = 0
delete = 0
delete = 0
delete = 0
delete = 0
delete = 0
delete = 0
delete = 0
delete = 0

in OnPluginInstall
delete = 0
delete = 30019
delete = 30019
delete = 30019
delete = 30019
delete = 30019
delete = 30019
delete = 30019
delete = 30019
delete = 30019


The first variable is always there (hence the result 0) because of the line:


SetVariable "World_Variable_1", "stuff"


... which is done after the deletes.

Try doing: world.debug "plugins" just before closing the plugin, to confirm that the variables are really deleted. Maybe the plugin puts them back.
Greece #4
I did, that's what surprised me. I put the notes just under the deletes/inserts, so I know they ran, but they were recreated every time I loaded the plugin... I didn't think to return the result of the DeleteVariable though, so maybe that failed. Now I can't test it, it doesn't do it any more. :( The variables were not in the file, because I deleted the state file and it runs ok now... I guess I should have reported it back then, but I thought I must be doing something wrong, and since it worked I didn't see any more trouble with it. :/