Jump to content

Struggling with LUA, table iterations


Recommended Posts

Posted (edited)

OK, n00b here. How the heck do I test and debug efficiently? As it is now I edit my script, goto DCS, reload the script in the trigger (DO SCRIPT FILE), start the mission and wait for things to happen/not happen. Is this how it needs to be done?

 

I am doing modifications to the Medevac script so that AI helicopters will spawn survivors differently (number of survivors & away from helicopter so as not to die from blast).

I have created the following table:

  helicopterlist = {
                       ["AB-212ASW"] = 4,
                       ["AH-1W"]  =  2,
                       ["AH-64A"]  =  2,
                       ["AH-64D"]  =  2,
                       ["CH-47D"]  =  5,
                       ["CH-53E"]  =  5,
                       ["OH-58D"]  =  2,
                       ["SH-3W"]  =  4,
                       ["SH-60B"]  =  4,
                       ["UH-60A"]  =  4,
                       ["UH-1H"]  =  4,
                       ["Ka-27"]  =  2,
                       ["Ka-50"]  =  1,
                       ["Ka-52"]  =  2,
                       ["Mi-24V"]  =  3,
                       ["Mi-26"]  =  5,
                       ["Mi-28N"]  =  2,
                       ["Mi-8MTV2"]  =  3
                   }

List edited for typenames errors.

It is each helicopter and it's number of crewmen. Is this format correct? The type is the index and the crew member count is the value.

I then try to iterate through this table in the event handler which the Medevac script creates but I get no output:

for helicopter, crews in pairs(helicopterlist) do
   trigger.action.outTextForCoalition(_woundcoal, "Checking if Unit is of type " .. helicopter, 10)
   if Unit.getTypeName(vnt.initiator) == helicopter then
       trigger.action.outText("Unit is of type " .. helicopter .. ". Crew number is " .. crews, 10)
   end
end

I do not get error messages nor do I get any output. Can someone give me some help? Pretty pleeeaaase?

 

Syntax corrected. This for loop works!

Edited by ArturDCS
Posted (edited)
Check your typenames as I can see at least one error in them at glance. Typename for Mi-8MTV2 is "Mi-8MT".

OK fixed!

 

The code if it was working should produce output regardless of string match. I can't understand why it's not working.

I have been trying with env.warning() type of output. Problem is the for loop doesn't iterate for some reason.

Edited by ArturDCS
Posted

The for-loop is ok, there's probably something before the for loop that crashes the code and stops execution. Add some debug messages before the for loop and find where it stops and then figure out why it stops.

DCS Finland: Suomalainen DCS yhteisö -- Finnish DCS community

--------------------------------------------------

SF Squadron

Posted
The for-loop is ok, there's probably something before the for loop that crashes the code and stops execution. Add some debug messages before the for loop and find where it stops and then figure out why it stops.

Yup I had a type in the syntax and I got it going. I have made good progress in the script. AI helicopters now request help.

I am now trying to get the number of survivors between 0 <-> random(0, crew member count) which is based on type of helicopter. After that it should be ready. (I hope) :)

Thanks!

  • Recently Browsing   0 members

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