Jump to content

attempt to compare number with error


Recommended Posts

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

Link to comment

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 

,

Link to comment

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.

Link to comment

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...