Daniels69 Posted January 21, 2017 Share Posted January 21, 2017 local bases = { {2412.8,92,26.47,1830.7,-1930.1,2955.6001,"garaza","playerserial"}, {1835.7,-1930.1,2955.6001,2412.8,92,26.40,"garaza2","playerserial"}, } and i need to get data out of the table, basically i want to contain all data about bases in table. Adding them manually , like in e.x above. but the problem is i don't know how to get data out of the table. for e.x i need these. local x,y,z = 2412.8,92,26.47 -- get the coordinates of first 3 values in the table local x1,y1,z1 = 1830.7,-1930.1,2955.600-- the 4,5,6 index in table password = "garaza2" -- get base password local ownerserial = "playerserial" -- last one , get base owner serial any one can help me? i need to fill those local x,y,z e.t.c with data from table for each base. Link to comment
LoPollo Posted January 21, 2017 Share Posted January 21, 2017 local table1 = {} table1[2] = someValue table.insert(table1, someValue2) --the lowest empty index is 1 (tables in lua starts from index 1) table1.somePosition = someValue3 if table1.somePosition == table1["somePosition"] then --this get executed end --table is now like { [1] = someValue2, [2] = someValue, somePosition = someValue3 } table1[1] --returns someValue2 table1[2] --returns someValue table1.somePosition --returns someValue3 table1["somePosition"] --return someValue3, as it's the same as above table1[3] --returns nil, no value was assigned here --tables can also have as index objects table1[localPlayer] = getPedOccupiedVehicle(localPlayer) if table1.localPlayer == table1[localPlayer] then --this WON'T be executed end if table1.localPlayer == table1["localPlayer"] then --this will be executed end NOTE: This is not MTA, this is lua. Next time search with google Link to comment
Daniels69 Posted January 21, 2017 Author Share Posted January 21, 2017 4 minutes ago, LoPollo said: local table1 = {} table1[2] = someValue table.insert(table1, someValue2) --the lowest empty index is 1 (tables in lua starts from index 1) table1.somePosition = someValue3 if table1.somePosition == table1["somePosition"] then --this get executed end --table is now like { [1] = someValue2, [2] = someValue, somePosition = someValue3 } table1[1] --returns someValue2 table1[2] --returns someValue table1.somePosition --returns someValue3 table1["somePosition"] --return someValue3, as it's the same as above table1[3] --returns nil, no value was assigned here --tables can also have as index objects table1[localPlayer] = getPedOccupiedVehicle(localPlayer) if table1.localPlayer == table1[localPlayer] then --this WON'T be executed end if table1.localPlayer == table1["localPlayer"] then --this will be executed end NOTE: This is not MTA, this is lua. Next time search with google i've tried it like this: local x,y,z = bases[1],bases[2],bases[3] local x1,y1,z1 = bases[4],bases[5],bases[6] password = bases[7] and it won't work Link to comment
LoPollo Posted January 21, 2017 Share Posted January 21, 2017 local bases = { {2412.8,92,26.47,1830.7,-1930.1,2955.6001,"garaza","playerserial"}, {1835.7,-1930.1,2955.6001,2412.8,92,26.40,"garaza2","playerserial"}, } --bases[1] = {2412.8,92,26.47,1830.7,-1930.1,2955.6001,"garaza","playerserial"} --so we have to do: local x,y,z = bases[1][1], bases[1][2], bases[1][3] --x,y,z are the data of the FIRST table: 2412.8, 92, 26.47 --do the same for the second table: local x2,y2,z2 = bases[2][1], bases[2][2], bases[2][3] Now do the same for the rest Link to comment
Daniels69 Posted January 21, 2017 Author Share Posted January 21, 2017 8 minutes ago, LoPollo said: local bases = { {2412.8,92,26.47,1830.7,-1930.1,2955.6001,"garaza","playerserial"}, {1835.7,-1930.1,2955.6001,2412.8,92,26.40,"garaza2","playerserial"}, } --bases[1] = {2412.8,92,26.47,1830.7,-1930.1,2955.6001,"garaza","playerserial"} --so we have to do: local x,y,z = bases[1][1], bases[1][2], bases[1][3] --x,y,z are the data of the FIRST table: 2412.8, 92, 26.47 --do the same for the second table: local x2,y2,z2 = bases[2][1], bases[2][2], bases[2][3] Now do the same for the rest if use createMarker with x,y,z , it doesnt work. Tried add tonumber() before bases[1][1] and then even in createMarker function. Dunno where is the problem. Link to comment
LoPollo Posted January 21, 2017 Share Posted January 21, 2017 (edited) Strange.... Try to output the x,y,z values to know what's in them Are there errors logged? (debugscript 3 or the .log file) Also did you follow the syntax of createMarker? Post the code block you used Edited January 21, 2017 by LoPollo grammar Link to comment
Daniels69 Posted January 21, 2017 Author Share Posted January 21, 2017 local bases = { {2412.8,92,26.47,1830.7,-1930.1,2955.6001,"garaza","playerserial"}, {1835.7,-1930.1,2955.6001,2412.8,92,26.40,"garaza2","playerserial"}, } local x,y,z = bases[1][1],bases[1][2],bases[1][3] local marker = createMarker ( x,y,z, "cylinder", 2, 82, 203, 54, 18, getRootElement() ) 10 minutes ago, LoPollo said: Strange.... Try to output the x,y,z values to know what's in them Are there errors logged? (debugscript 3 or the .log file) Also did you follow the syntax of createMarker? Post the code block you used Link to comment
LoPollo Posted January 21, 2017 Share Posted January 21, 2017 i can't see any error... but alpha is 18 so maybe you can't see it due to transparency? Link to comment
JamieSA Posted January 21, 2017 Share Posted January 21, 2017 is this man just asking for a simple loop through his data table? Just loop through your data table and do what you need to do with each row function mytrigger() local bases = { {2412.8,92,26.47,1830.7,-1930.1,2955.6001,"garaza","playerserial"}, {1835.7,-1930.1,2955.6001,2412.8,92,26.40,"garaza2","playerserial"}, } for key, value in ipairs(bases) do local x,y,z,x1,y1,z1,password,ownerserial = value[1],value[2],value[3],value[4],value[5],value[6],value[7],value[8] -- do your workings with each row here outputConsole(tostring(ownerserial)) end end addCommandHandler ( "mytrigger", mytrigger ) I've added a command handler so you can output the result to the console for testing yourself. When outputting to the console be sure to use tostring() for any value that is not a string already 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