ertlflorian1 Posted May 8, 2013 Share Posted May 8, 2013 How i can get from the string veh1 or veh2 the car veh1 and veh2? local veh1 = createVehicle (...) local veh2 = createVehicle (...) for i=1, 2 do local name = "veh"..i local x, y, z = getElementPosition (name) outputChatBox (x..", "..y..", "..z) end Link to comment
50p Posted May 8, 2013 Share Posted May 8, 2013 Better way is to use tables instead: local vehs = { createVehicle( ... ), createVehicle( ... ) }; for _, veh in pairs( vehs ) do local x,y,z = getElementPosition( veh ); outputChatBox( x .. ", " .. y .. ", " .. z ); end If you really want to get variables by their names you can use global table (_G) but I do not recommend it because in some cases this will return nil: local veh1 = createVehicle( ... ); outputChatBox( "Vehicle name: " .. getVehicleName( _G["veh1"] ) ) 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