WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   LUA adding a minus sign to a 0 value. Help! (https://www.wowinterface.com/forums/showthread.php?t=38653)

Zealer 01-30-11 12:58 PM

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

Seerah 01-30-11 01:06 PM

What is the code?

Zealer 02-01-11 06:09 PM

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.

Zealer 02-01-11 06:23 PM

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.

Zealer 02-01-11 06:55 PM

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.

Zealer 02-01-11 06:58 PM

"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?

Rilgamon 02-01-11 07:45 PM

Quote:

Originally Posted by Zealer (Post 228388)
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.

Zealer 02-01-11 07:55 PM

Code
 
Ah yeah,

Just a typo in the thread, the code does have the ==

Saiket 02-01-11 08:46 PM

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.


All times are GMT -6. The time now is 12:50 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI