Jump to content

Getting key of the specified value in a table


NeverGiveup

Recommended Posts

jobSheet = { 
    ['fisherman'] = "Fisherman",  
    ['medic'] = "Paramedic",  
    ['lumberjack'] = "Lumber Jack", 
} 
    function thisshit() 
        jobitself = getKeyFromValueInTable(jobSheet, "Fisherman") 
        outputChatBox(tostring(jobitself)) 
    end 
    addEventHandler("onResourceStart", getRootElement(), thisshit) 
     
function getKeyFromValueInTable(a, b) 
    for k,v in ipairs(a) do 
        if v == b then 
           return k 
        end 
    end 
    return false 
end 

So I used a function which is https://wiki.multitheftauto.com/wiki/Ge ... lueInTable , but I got a problem using this function, from code above it always returns false. Why is that so?

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