Reachless Posted September 10, 2017 Share Posted September 10, 2017 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
Reachless Posted September 10, 2017 Author Share Posted September 10, 2017 (edited) Nevermind. Found out about function getElementByIndex. If anyone is wondering, to get the vehicle element with ID 1 you need to use getElementByIndex("vehicle", 1). I love Lua. Edited September 10, 2017 by Reachless Link to comment
Mr.Loki Posted September 10, 2017 Share Posted September 10, 2017 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now