FuriouZ Posted June 1, 2014 Posted June 1, 2014 Hello! I have problem, i don't know how to set up table.. I need to get engine state randomly from table like 1 = true, 2 = false, but I don't understand how to do it local engineStates = { [ 1 ] = true, [ 2 ] = false, } local state = unpack ( engineStates [ math.random ( #engineStates ) ] ) setVehicleEngineState ( source, state ) Thanks!
ixjf Posted June 1, 2014 Posted June 1, 2014 You can't unpack a boolean, the unpack function only unpacks tables (if you think in it, it makes complete sense). It should be like this: setVehicleEngineState ( source, engineStates[ math.random ( #engineStates ) ] ) I hope your code isn't designed the way you showed, you shouldn't be defining the table whenever that code is executed, rather define it once in a place that can be accessed by that piece of code. The current way works, but the fact that it works doesn't mean you should do it that way.
#RooTs Posted June 1, 2014 Posted June 1, 2014 local engineStates = { [ 1 ] = true, [ 2 ] = false, } setVehicleEngineState ( source, engineStates[ math.random ( #engineStates ) ] ) well?
Cadell Posted June 1, 2014 Posted June 1, 2014 I think you need to try this Table = {} Table[1]={true} Table[2]={false} for i, v in pairs(Table) do setVehicleEngineState ( theVehicle, math.random(v) ) end If it wont work tell me as i didnt tested it
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