Jump to content

Table contacting ...


3B00DG4MER

Recommended Posts

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 by Guest
Link to comment

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 by Guest
Link to comment

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...