Sex* Posted April 16, 2013 Posted April 16, 2013 Then two people on the server or more i have these errors: 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
DiSaMe Posted April 16, 2013 Posted April 16, 2013 That means distanceFromPlayerToCheckpoint returns nil. -
Sex* Posted April 16, 2013 Author Posted April 16, 2013 But how to fix it then? EDIT: So i add something like this? g_Checkpoints = nil
Moderators IIYAMA Posted April 19, 2013 Moderators Posted April 19, 2013 = distanceFromPlayerToCheckpoint(player, sortinfo[i].checkpoint ) or 0 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Sex* Posted April 20, 2013 Author Posted April 20, 2013 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 )
Moderators IIYAMA Posted April 20, 2013 Moderators Posted April 20, 2013 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. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now