Jump to content

need help with tables


isa_Khamdan

Recommended Posts

I have error in line 13 saying that expected table got nil while I do have a table named Vehicle1

and I checked it using outputChatBox so can anyone help me to solve it?

  
  
addEventHandler("onPlayerChat",root, 
    function (msg,type) 
        if ( type == 0 and msg == "test" ) then 
        if ( isStarted == true ) and ( readyPlayers < maxPlayers ) and not isPedInVehicle(source) and not getElementData(source, "inMissionD" ) == true then 
        cancelEvent() 
        readyPlayers = ( readyPlayers + 1 )  
        VarName = ("vehicle"..readyPlayers) 
        setElementData(source, "inMissionD", true) 
        VarX = ("Vehicles"..vMap) 
        outputChatBox(VarX) 
        local x, y, z, rx, ry, rz  = unpack ( VarX [ readyPlayers ] ) 
        VarName = createVehicle ( vID, x, y, z, rx, ry, rz ) 
        table.insert(DVeh,VarName) 
        warpPedIntoVehicle ( source, VarName) 
        setElementData( source, "isBlocked", true, true) 
        toStart() 
        return 
        end 
    end 
end 
) 

Link to comment

that's the table

Vehicles1 = { 
 [1]={ 2902.6318359375, -2043.0684814453, 3.208420753479, 0, 0, 270 }, 
 [2]={ 2902.5588378906, -2046.3167724609, 3.208420753479, 0, 0, 270 }, 
 [3]={ 2902.4799804688, -2049.8156738281, 3.208420753479, 0, 0, 270 }, 
 [4]={ 2902.4121093755, -2052.8154296875, 3.208420753479, 0, 0, 270 }, 
 [5]={ 2902.3391113281, -2056.0654296875, 3.208420753479, 0, 0, 270 } 
  
} 

Link to comment

What you are trying to do is not going to work, make your table this format:

vehicles = 
    { 
        [ 1 ] = 
        { 
            [1]={ 2902.6318359375, -2043.0684814453, 3.208420753479, 0, 0, 270 }, 
            [2]={ 2902.5588378906, -2046.3167724609, 3.208420753479, 0, 0, 270 }, 
            [3]={ 2902.4799804688, -2049.8156738281, 3.208420753479, 0, 0, 270 }, 
            [4]={ 2902.4121093755, -2052.8154296875, 3.208420753479, 0, 0, 270 }, 
            [5]={ 2902.3391113281, -2056.0654296875, 3.208420753479, 0, 0, 270 } 
        } 
    } 

Then change this:

VarX = ("Vehicles"..vMap) 

Into:

VarX = vehicles [ vMap ] 

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