Jump to content

Lua table


Recommended Posts

Tabel is easy thing, where u can store items, arguments, everything what u would like to.

With tabel, u can make much more easyly big items, lets make u example.

myTabel = {{"Infernus", "0", "0","3"}{"Alpha", "0", "3","3"}}   
-- So, tabel is now done with Car name, and cords. 
function createVehicles () 
  for i,v in ipairs ( myTabel ) do -- gets all items in tabel 
    local carID = getVehicleModelFromName(v[1]) 
    local vehicle[i] = createVehicle ( carID, tonumber([v2]), tonumber([v3]), tonumber([v4])) 
  end 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createVehicles ) 

Hope it helps a bit u.

EDIT: Read that too... :Dhttp://lua-users.org/wiki/TablesTutorial

Link to comment

getVehicleHandling returns a table indeed. If you do the following:

local handlingTable = getVehicleHandling ( veh ) 

and you want to get the mass value, you usew the following:

handlingTable["mass"] 

the centerOfMass is a bit trickier, as that returns a table itself. So, in order to get the Z position of centerOfMass, use the following:

vehicleTable["centerOfMass"][3] -- Numbers: 1 = X, 2 = Y, 3 = Z 

Yes, a nested table :)

But you ifyou dont want to get a complete table, and just retrieve the mass you could also use this:

getVehicleHandling ( veh )["mass"] 

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