3B00DG4MER Posted March 31, 2015 Share Posted March 31, 2015 (edited) Hi Guys, today i wanted to make a job system .... so i had that table {{3,1},{22,100}} i wanted to make it draw the first of first table and first of second table as weapon and second of first table and sec of sec table as ammo { {Weapon, Ammo}, {Weapon, Ammo} } i tried this dxDrawText("Weapons :#FFFFFF ".. table.foreachi(JobsData[3],function(k,v) return getWeaponNameFromID(v[1]).." - Ammo:"..v[2].."\n" end),10,320,10,320,tocolor(0,200,200,255),1,Core.TinyFont,"left","top",false,false,false,true) Edited March 31, 2015 by Guest Link to comment
Addlibs Posted March 31, 2015 Share Posted March 31, 2015 (edited) Your messages does not make much sense... Two values for "weapon" and two values for "ammo"? Explain a bit more. Edit: Do you want to have all weapons listed in a comma separated list? Then try local _weapons = {} for k, v in ipairs(the_table) do table.insert(weapons, getWeaponNameFromID(v[1])) end "Weapons: "..table.concat(weapons, ", ") Edited March 31, 2015 by Guest Link to comment
WhoAmI Posted March 31, 2015 Share Posted March 31, 2015 table = {{3,1},{22,100}} local weapon, ammo = unpack ( table[1] ) Well, i'm not sure if I am right. Link to comment
3B00DG4MER Posted March 31, 2015 Author Share Posted March 31, 2015 i wanted to put Weapon : - Ammo: Weapon : - Ammo: Weapon : - Ammo: Weapon : - Ammo: ... Link to comment
WhoAmI Posted March 31, 2015 Share Posted March 31, 2015 If so you have to loop through the table. table = {{3,1},{22,100}} for _, v in pairs ( table ) do if ( type ( v ) == "table" ) then local weapon, ammo = v[1], v[2] if ( weapon and ammo ) then dxDrawText ( weapon .." " .. ammo, 0, 0 ) end end end Link to comment
3B00DG4MER Posted March 31, 2015 Author Share Posted March 31, 2015 I wanted to make in one text (dxDrawText) cuz i'm making it with math things .. Link to comment
WhoAmI Posted March 31, 2015 Share Posted March 31, 2015 So do like that: local table = {{3,1},{22,100}} local text = "" for _, v in pairs ( table ) do if ( type ( v ) == "table" ) then local weapon, ammo = v[1], v[2] text = "Weapon: " .. weapon .. " Ammo: " .. ammo .. "\n" .. text end end dxDrawText ( text, 0, 0 ) Link to comment
3B00DG4MER Posted March 31, 2015 Author Share Posted March 31, 2015 Thanks works But why you need to check if it's table while it's a table (i did check that before) Link to comment
WhoAmI Posted March 31, 2015 Share Posted March 31, 2015 Just in case when in 'table' won't be another table, just to prevent errors. 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