Jump to content

Trouble with accessing array of vehicles


Reachless

Recommended Posts

Let's say I have the following array 'vehicles':

local vehicles = { }
local vehicle
for i=1,10 do -- ( considering I have no vehicle spawned on the server before executing this code )
    vehicle = createVehicle( 522, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, "mta" ) -- dont mind the parameters, it's just mockup data
    vehicles[vehicle] = { testvar = 1 }
end

Let's say outside this code, I want to access the "testvar" variable for vehicle ID 1. How can I do that? I have tried doing the following:

outputChatBox(type((vehicles[1]).testvar)) -- vehicles[1] is nil

..but vehicles[1] seems to be nill.

Link to comment
local vehicles = { }
local vehicle
for i=1,10 do -- ( considering I have no vehicle spawned on the server before executing this code )
  local vehicle = createVehicle( 522, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, "mta" ) -- dont mind the parameters, it's just mockup data
  table.insert(vehicles,vehicle)
end

iprint(vehicles[1])
-- outputs the first vehicle element in the table to the debug

 

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