Skip to content

getCar

Returns a reference to a car’s state structure. This is the starting point for almost any script interacting with vehicles.

ac.getCar(index)

This function provides access to the ac.StateCar object for a specific vehicle in the session. Vehicle indices are 0-based.

ParameterTypeRequiredDefaultDescription
indexintegerYes-The 0-based index of the car.
TypeDescription
ac.StateCarA reference to the car’s data. Returns nil if the index is invalid.
  • Performance: Calling ac.getCar is extremely cheap (it returns a pointer to a pre-allocated FFI struct). However, it is still best practice to cache the reference if you use it many times in a single loop.
  • Thread Safety: In physics scripts, this data is updated at the physics rate. In UI scripts, it is updated at the frame rate.
local car = ac.getCar(0)
if car.speedKmh > 100 then
ac.log("Fast!")
end