Thread Tools Display Modes
05-04-17, 02:48 PM   #1
GeodesicDragon
A Defias Bandit
 
GeodesicDragon's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 3
[RESOLVED] Code Not Treating A Number As A Number

I'm a big nerd, and I like statistics. My anti-duel addon, DuelResponse, tracks how many duels it blocks across all characters, as well as per character.

It does this with two variables:
  • GlobalDC (all characters)
  • DuelsDeclined (per character)

I've added a button to the new Options menu I added in version 4.0.0 which will allow you to reset these numbers. However, since 'DuelsDeclined' is saved on a per-character basis, that would mean having to perform the reset every time you logged into another character.

To prevent that, I wrote a little function which would do it for you.

Code:
function resetcheck()

local x = tonumber(GlobalDC) -- number of duel requests blocked across all of your characters characters
local y = tonumber(DuelsDeclined) -- number of duel requests blocked on the character you are playing

-- Check to see if the all character counter has been reset to zero, and if the local counter is greater than zero.
-- If both of these conditions are true, then reset the local counter to zero.
if x == 0 and y > 0 then
	y = 0
	DuelsDeclined = y
end

end
However, it's not working. For some reason, the function doesn't seem to register 'y' as a number, even though I am telling it to. I was on my Monk at the time of posting this, and she has had 17 duel requests blocked; I added a line of code to the above to display 'y' in a message box, and it said '0.'

I cannot for the life of me figure out what is going on, as I do not see anything wrong with my code. Then again, this is me we're dealing with, so chances are high that I have in fact overlooked something.

Thanks in advance for any help. If you have any questions, please feel free to ask.
__________________
Lua Code:
  1. function ShowSignature()
  2. print("Creator of DuelResponse, Free Bag Space, Guild and Faction Tooltip, XP Bar Text, Easy Portal Advert and Selfie Helper.")
  3. end

Last edited by GeodesicDragon : 05-04-17 at 04:17 PM. Reason: Resolved.
  Reply With Quote
05-04-17, 03:52 PM   #2
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Did you wait for your addon to load before doing the checkup?
Saved variables are loaded when the event ADDON_LOADED fires for your particular addon and not before that. Attempting to grab the variable from the global environment before it exists would result in it being nil.

Btw, if you're storing your variables as plain numbers, you do not need to use tonumber.
__________________
  Reply With Quote
05-04-17, 04:17 PM   #3
GeodesicDragon
A Defias Bandit
 
GeodesicDragon's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 3
Originally Posted by MunkDev View Post
Did you wait for your addon to load before doing the checkup?
... excuse me while I go and headdesk until I knock myself out.

Thanks.
__________________
Lua Code:
  1. function ShowSignature()
  2. print("Creator of DuelResponse, Free Bag Space, Guild and Faction Tooltip, XP Bar Text, Easy Portal Advert and Selfie Helper.")
  3. end
  Reply With Quote
05-04-17, 04:44 PM   #4
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
For future reference, if you want access to your saved per-character data on another character, just save the data in a key named after that character in the account variable. To wipe all data, just wipe the table.

Example:

Code:
AccountSavedVariables={
    ["Main-Lightbringer"]=4
    ["Altguy-Blackrock"]=7
}

When you login, just have the code use local name,realm=UnitFullName("player") local playername=name.."-"..realm and you have your key. Also, this way you don't need to save an account-wide number, just iterate through the table and add them all up.

Last edited by Kanegasi : 05-04-17 at 04:46 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » [RESOLVED] Code Not Treating A Number As A Number


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off