Jump to content

attempt to compare number with error


Recommended Posts

Posted
function getPlayerPoints (thePlayer) 
local Points = loadPlayerData (thePlayer,"wins") 
if (Points <= 0 ) then 
 savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
elseif (Points <= 100 ) then 
 savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
elseif (Points <=250 ) then 
 savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
elseif (Points <= 500 ) then 
 savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
elseif (Points <= 1000 ) then 
 savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
elseif (Points <= 2500 ) then 
 savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
elseif (Points <= 5000 ) then 
 savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
elseif (Points <= 10000 ) then 
 savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
elseif (Points <= 50000 ) then 
 savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
elseif (Points <= 1000000 ) then 
 savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
end 
end 

Line 3 error pls help attempt to compare number with error

emegesaygi6.gif
Posted

What do you mean? i don't get you. :roll:

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

I think you did this wrong

(Points <= 0 ) 

Try this

function getPlayerPoints (thePlayer) 
local Points = loadPlayerData (thePlayer,"wins") 
if (Points > 0 ) then 
 savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
elseif (Points > 100 ) then 
 savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
elseif (Points > 250 ) then 
 savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
elseif (Points > 500 ) then 
 savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
elseif (Points > 1000 ) then 
 savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
elseif (Points > 2500 ) then 
 savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
elseif (Points > 5000 ) then 
 savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
elseif (Points > 10000 ) then 
 savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
elseif (Points > 50000 ) then 
 savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
elseif (Points > 1000000 ) then 
 savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
       end 
end 

,

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

Posted

Jaysds1 this will not work, because as long as you have more than 0 points, the IF statement will always pass at the first check. If you want to set ranks like this, the highest rank (1,000,000 points) needs to be the FIRST in the IF statement, then the 50,000 points rank, then the 10,000, etc.

  
function getPlayerPoints (thePlayer) 
local Points = loadPlayerData (thePlayer,"wins") 
if (Points > 1000000 ) then 
    savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
elseif (Points > 50000 ) then 
   savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
elseif (Points > 10000 ) then 
   savePlayerData (thePlayer,"rank",loadPlayerData(thePlayer,"rank") + 1) 
 -- and so on....  

The loadPlayerData and savePlayerData functions are from jasperNL's pointsystem resource on the community, which saves data to an XML file (unless he changed it).

For a ranking system like this you should use a table to set the next rank instead of checking for points all the time.

You will have to post the loadPlayerData function so we can see if you have an error in there.

On the other hand, you could just have an error somewhere in the code. I never saw "attempt to compare error with a number" message in the debugging window.

Website: http://www.twisted-gamers.net

Don't you just love the error messages in LUA?

notmem11.png

Posted

I suposed they we're from Jasper's resource :P

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...