Jump to content

Checking if car's model is in table


Recommended Posts

Hello guys.

I'm not good at tables. That's why i have problem.

I have sth like this:

availible_cars = { 403, 413, 414, 433, 440, 455, 456, 459, 498, 499, 514, 515, 578, 609 } 
for k,v in ipairs (availible_cars) do 
if v == getElementModel(veh) then 
outputChatBox("true") 
else 
outputChatBox("false") 
end 
end 

Don't ask me if I definied veh couse i did it in my normal code. But problem is in "else" of the "if". When car's model isn't in the table it is outputing about 14 times message "false". Is there a possibility to do this in another way without "for"? And is this code correct?

Link to comment
local availible_cars = { 
    [403]=true, [413]=true, [414]=true, [433]=true, [440]=true,  
    [455]=true, [456]=true, [459]=true, [498]=true, [499]=true,  
    [514]=true, [515]=true, [578]=true, [609]=true 
} 
     
if availible_cars[getElementModel(veh)] then 
    outputChatBox("true") 
else 
    outputChatBox("false") 
end 

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