Jump to content

Recommended Posts

Posted

So I have this idea of a simple BDA check and I put destroyed unitTypeName in a table but I cant get the iteration to work right. What I want is a result like:

 

Shilka: 2

Strela: 2

 

But I only get the last added table entry to display:

 

Strela: 2

 

Below is my sample script. Extra outtexts in sample for checking that the adding to table works in game, and it does seem to. But what am I doing wrong with the iteration (last threee lines?)

 

local BDA = {}

local unitTypeName = 'Shilka'
				
if not BDA[unitTypeName] then
BDA = {[unitTypeName]=1}
trigger.action.outText('Added new unittype ' .. unitTypeName .. ' to BDA count',3)
else
BDA = {[unitTypeName]=BDA[unitTypeName]+1}
trigger.action.outText('Added existing unittype ' .. unitTypeName .. ' to BDA count',3)

end

if not BDA[unitTypeName] then
BDA = {[unitTypeName]=1}
trigger.action.outText('Added new unittype ' .. unitTypeName .. ' to BDA count',3)
else
BDA = {[unitTypeName]=BDA[unitTypeName]+1}
trigger.action.outText('Added existing unittype ' .. unitTypeName .. ' to BDA count',3)

end

unitTypeName = 'Strela'

if not BDA[unitTypeName] then
BDA = {[unitTypeName]=1}
trigger.action.outText('Added new unittype ' .. unitTypeName .. ' to BDA count',3)
else
BDA = {[unitTypeName]=BDA[unitTypeName]+1}
trigger.action.outText('Added existing unittype ' .. unitTypeName .. ' to BDA count',3)

end

if not BDA[unitTypeName] then
BDA = {[unitTypeName]=1}
trigger.action.outText('Added new unittype ' .. unitTypeName .. ' to BDA count',3)
else
BDA = {[unitTypeName]=BDA[unitTypeName]+1}
trigger.action.outText('Added existing unittype ' .. unitTypeName .. ' to BDA count',3)

end

for k,v in pairs(BDA) do
trigger.action.outText(k .. ': ' .. v,5)
end

GPU: PALIT NVIDIA RTX 3080 10GB | CPU: Intel Core i7-9700K 4,9GHz | RAM: 64GB DDR4 3000MHz
VR: HP Reverb G2 | HOTAS: TM Warthog Throttle and Stick
OS: Windows 10 22H2

Posted

When you write:

BDA = {[unitTypeName]=1}

you replace the whole BDA with a table with a single entry.

What you want is:

BDA[unitTypeName] = 1

Posted

Thanks man! That did the trick!

 

rikkles rep +10 :)

GPU: PALIT NVIDIA RTX 3080 10GB | CPU: Intel Core i7-9700K 4,9GHz | RAM: 64GB DDR4 3000MHz
VR: HP Reverb G2 | HOTAS: TM Warthog Throttle and Stick
OS: Windows 10 22H2

  • Recently Browsing   0 members

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