Thread Tools Display Modes
01-30-11, 12:58 PM   #1
Zealer
A Deviate Faerie Dragon
Join Date: Nov 2010
Posts: 16
LUA adding a minus sign to a 0 value. Help!

Hi Everyone,

I seem to be stuck where somehow, a minus sign is being added to a saved variable when it's 0. Best as I can tell, when loading the variable it adds the minus sign. I can't figure out why. Anyone have any suggestions? I've manually edited the saved variable file to make the variable just 0 but when I print the variable it says -0.
Any help is appreciated!

Thanks
  Reply With Quote
01-30-11, 01:06 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
What is the code?
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
02-01-11, 06:09 PM   #3
Zealer
A Deviate Faerie Dragon
Join Date: Nov 2010
Posts: 16
Code

I believe this is the first line accessing the data after its loaded:
local playerEP = WebDKP_DkpTable[playerName]["ep_"..tableid];
I manually modify the saved variable file to just 0 instead of -0 and have a whisper command after that to see what it gets. For 0 it returns -0 for all other positive values, they stay positive. It's pretty annoying.
  Reply With Quote
02-01-11, 06:23 PM   #4
Zealer
A Deviate Faerie Dragon
Join Date: Nov 2010
Posts: 16
Issue

Seems like I've isolated it down to where it loads the array from the save variable. When I log out of the game the value is saved correctly as 0. When I go back into the game the value turns into -0.
  Reply With Quote
02-01-11, 06:55 PM   #5
Zealer
A Deviate Faerie Dragon
Join Date: Nov 2010
Posts: 16
More info

I set up an if statement to print a message if the variable was equal to 0. It was true so it does treat -0 as 0. Unfortunately I don't want it to be displayed as -0 if print it to the screen. Pretty annoying since there is no such thing as -0.
  Reply With Quote
02-01-11, 06:58 PM   #6
Zealer
A Deviate Faerie Dragon
Join Date: Nov 2010
Posts: 16
"fix"

Alright,
I think there must be some sort of glitch with the api or whatever backend function loads values from the saved vars.
Here is how I am getting around the -0:

if playerEP == 0 then
playerEP = 0;
end

Pretty hilarious. Anyone else seen this?

Last edited by Zealer : 02-01-11 at 07:56 PM.
  Reply With Quote
02-01-11, 07:45 PM   #7
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Originally Posted by Zealer View Post
Alright,
I think there must be some sort of glitch with the api or whatever backend function loads values from the saved vars.
Here is how I am getting around the -0:

if playerEP = 0 then
playerEP = 0;
end

Pretty hilarious. Anyone else seen this?
if there are more places like this in your code it would be better to show your code so others can take a look when you compare values you need the == operator.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
02-01-11, 07:55 PM   #8
Zealer
A Deviate Faerie Dragon
Join Date: Nov 2010
Posts: 16
Code

Ah yeah,

Just a typo in the thread, the code does have the ==
  Reply With Quote
02-01-11, 08:46 PM   #9
Saiket
A Chromatic Dragonspawn
 
Saiket's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 154
If you round the value before printing, it should go away. You could use something like print( floor( Value * 100 + 0.5 ) / 100 ) to round to 2 decimal places. I tested that with a manually entered -0 and it gave back 0.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » LUA adding a minus sign to a 0 value. Help!


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