PDA

View Full Version : Saved Variable existance check...


Psycowtic
13-06-2007, 05:41 PM
Hey guys,
Right now with Honorgrind 2.0 all the stats are saved in the saved variables file, which is great, but because that file isn't created until after I quit or reload I'm getting some nil value errors. Is there any way to test if the saved variables exist or not and if they don't initialize some local values until they are created?

I'm not sure if I explained that right but I hope someone understands through some sort of miracle :)

Edit:
BTW the nil value errors only occur the very first session because after that the file is created. What's weird is that even with a fresh install of the mod, it runs perfectly on my main toon.

Jumpy
13-06-2007, 06:19 PM
if variable == nil then
variable = value
end

Psycowtic
13-06-2007, 06:58 PM
tried that, it gives me an error when it tries to access the variable to compare it.

Psycowtic
13-06-2007, 06:59 PM
I think this is the way it's going to have to be for Titan Panel HonorGrind 2.0. But for 3.0 I was thinking about rewriting the entire thing with a proper UI options menu and itemlinks and not relying on saved variable files to store databases.

aspinkorgall
13-06-2007, 07:37 PM
tried that, it gives me an error when it tries to access the variable to compare it.

I've used that plenty of times to see if a variable exists yet and never had any issues. Perhaps you can post your code, or at least that section of it?

Psycowtic
13-06-2007, 07:41 PM
hmm...
I'll post it once I get back on my other comp. If it works I'll take another look, thanks guys.

Duugu
14-06-2007, 02:00 AM
if not SavedVar then
SavedVar = "whatever"
end

Psycowtic
18-06-2007, 03:21 AM
Fixed, I just made some local variables to correspond with the saved ones and everytime a local one changed, the saved one was changed as well, but I switched all the checks to use the locals instead of saved variables.

Telic
23-06-2007, 12:39 PM
Someone has suggested the following code :

if not SavedVar then
SavedVar = "whatever"
end


This can be a dangerous habit leading to the resetting of boolean SavedVar values - the first reply in the thread was a much safer method :

if variable == nil then
variable = value
end