Jump to content

for in pairs() do


kuwalda

Recommended Posts

If I am storing players name and race time like this in table:

blueBerryRallyP[thePlayer] = ((getTickCount () - getElementData( thePlayer, "laiks" )) / 1000) 

Why does this not work:

function endRace(raceToEnd) 
    outputChatBox("Ending:"..raceToEnd..".", root, 0, 255, 255) 
    function findRaceWinner(blueBerryRallyP) 
        if blueBerryRallyP and type(blueBerryRallyP) == 'table' then 
            local time, winner = math.huge 
            for thePlayer, theTime in pairs(blueBerryRallyP) do 
                outputChatBox("INDEX "..thePlayer..", ar VALUE: "..theTime ) 
                if theTime < time then 
                    winner, time = thePlayer, theTime            
                end 
            end 
            return winner, time 
        end 
        return false 
    end 
end 

It just shows outputChatBox("Ending:"..raceToEnd..".", root, 0, 255, 255) line and thats all.

Link to comment

Yes, it worked now. Silly question, but how can I use this function to get those returned values?

function findRaceWinner(raceToEnd) 
        if blueBerryRallyP and type(blueBerryRallyP) == 'table' then 
            local time, winner = math.huge 
            for thePlayer, theTime in pairs(blueBerryRallyP) do 
                if theTime < time then 
                    winner, time = thePlayer, theTime            
                end 
            end 
            return winner, time 
        end 
        return false 
end 

Like how can I get or use those return winner, time values?

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