Jump to content

Debugscript throwing errors


Sex*

Recommended Posts

Then two people on the server or more i have these errors:

0102035961fb8ef.jpg

198 line function:

function RaceMode:updateRanks() 
        -- Make a table with the active players 
        local sortinfo = {} 
        for i,player in ipairs(getActivePlayers()) do 
                sortinfo[i] = {} 
                sortinfo[i].player = player 
                sortinfo[i].checkpoint = getPlayerCurrentCheckpoint(player) 
                sortinfo[i].cpdist = distanceFromPlayerToCheckpoint(player, sortinfo[i].checkpoint ) 
        end 
        -- Order by cp 
        table.sort( sortinfo, function(a,b) 
                                                return a.checkpoint > b.checkpoint or 
                                                           ( a.checkpoint == b.checkpoint and a.cpdist < b.cpdist ) 
                                          end ) 

The 198 line:

                                                           ( a.checkpoint == b.checkpoint and a.cpdist < b.cpdist 

Link to comment

So something like this?

function RaceMode:updateRanks() 
        -- Make a table with the active players 
        local sortinfo = {} 
        for i,player in ipairs(getActivePlayers()) do 
                sortinfo[i] = {} 
                sortinfo[i].player = player 
                sortinfo[i].checkpoint = getPlayerCurrentCheckpoint(player) 
                sortinfo[i].cpdist = distanceFromPlayerToCheckpoint(player, sortinfo[i].checkpoint ) 
        end 
        -- Order by cp 
        table.sort( sortinfo, function(a,b) 
                                                return a.checkpoint > b.checkpoint or 
                                                           ( a.checkpoint == distanceFromPlayerToCheckpoint(player, sortinfo[i].checkpoint ) or 0 
                                          end ) 

Link to comment
  • Moderators

I don't know why you return a boolean to table.sort, it is probably because I got another scripting style and I haven't used it that much.

try this:

table.sort( sortinfo, function(a,b) 
    return a.checkpoint > b.checkpoint or  
    ( a.checkpoint == (tonumber(distanceFromPlayerToCheckpoint(player, sortinfo[i].checkpoint)) or 0))  
end ) 

updated.

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