Jump to content

Trouble getting trigger.action.activateGroup() to work


Go to solution Solved by esb77,

Recommended Posts

Posted

I've got a mission I'm working on where I'm trying to have delayed activation client aircraft.    I've done missions before where I've used the ME triggers to do this successfully, but the conditions are more complicated, and ideally I'd like to spawn in up to 60 or so units and therefore I'd rather do the activation with a script, instead of creating a massive amount of triggers in ME.

 

So my approach so far as been:

Create a table of groups to spawn   in a ONCE   At Mission Start trigger.

--migSpawn Test code
-- objective: assuming that a global variable named mig29ActivationIndex has been initialized with a value of zero at mission start
--  have a reapeating trigger activate a series of delayed start groups in response to a specific condition
-- and display a counter of how many groups have been activated so far.

--Create an integer indexed table with the names of the groups that are to be spawned,  note for performance reasons this probably shouldn't be in a reapeating trigger in the actual mission, create the table in an initialization trigger and make the table global

migGroupsToActivate = {}   --table with names of mig groups to activate.
local groupRootName = "Mig "
local numbGroupsInTable = 5   -- enter how many groups of migs are to be delayed activated in the mission
local groupIndexStart = 1
local indexValue = 1                                                 --if the table values are Root_i  this is the value of the current subscript
for increment = groupIndexStart, numbGroupsInTable, 1  do     -- starting at the index start, stopping when the index is equal to numbGroupsInTable with a step size of one
  table.insert(migGroupsToActivate, groupRootName .. indexValue)  -- in table migGroupsToActivate for the next integer key  enter the value groupRootName concatenated with the current indexValue
  indexValue = indexValue + 1
end
 
local tableValueTest = migGroupsToActivate[4]
      trigger.action.outText(tableValueTest, 20, false)       --checking that the table of mig groups exists and has valid value fields

This part seems to be working.  I get returns from the outText action that look like what I expect them to.

 

Then in a separate trigger  I have an if then structure to examine a global variable, and if true, advance a counter that starts at 0, and then activate the group from the table of group names along with a message to let me (and eventually players in the mission) know that the unit has been activated and is available.

  if speedViolation > 1 then                                     --if a speeder was detected in the speed monitoring section
    mig29ActivationIndex = mig29ActivationIndex + 1                 --increment the global variable that counts the index of how many mig groups have been activated. 
	trigger.action.outText("Activation index = " .. mig29ActivationIndex, 20, false)  --debugging line, test that index is advancing properly
    local	nextMigGroup = migGroupsToActivate[mig29ActivationIndex]         --use the mig index as an input to find the i th  group in the mig groups table
    trigger.action.outText(nextMigGroup, 20, false)                   --debugging did I capture the value from the groups table
    trigger.action.activateGroup(nextMigGroup)                        --activate that group
    trigger.action.outText("Mig 29 unit: " .. mig29ActivationIndex .. " activated.", 20, false)     --message players that the group has been activated.
	speedViolation = 0   	-- reset the speed violation variable for the next monitoring loop.

   end

It didn't work of course, which is how all my lines of code normally start out.  I have debugged as far as

trigger.action.activateGroup(nextMigGroup)

and everything up to there seems to be working as I expect.

I didn't entirely understand the error message:

ActivateGroupError1.png

So I made a new mission, set up a ONCE trigger, TIME MORE (10) condition, and Do Script

trigger.action.activateGroup("Aerial-1")

to have the simplest possible version of the activate script, and I get this

activateGroupErrorMessage.png

 

So having tried to simplify this as much as possible, it looks to me like when I use  trigger.action   and append .activateGroup to it, DCS looks for a method called "activate" and can't find it?

So the questions are:  Am I interpreting that error correctly?   and   How do I help the scripting environment find the activateGroup method?

 

I'm getting reasonably good at figuring out how my incorrect input types make script functions not work (I get lots of practice), but not being able to call a script function is a first for me, and I'm not quite sure how to approach debugging that.

 

I'm working off of https://wiki.hoggitworld.com/view/DCS_func_activateGroup this as documentation for activateGroups.   

Callsign "Auger". It could mean to predict the future or a tool for boring large holes.

 

I combine the two by predictably boring large holes in the ground with my plane.

  • Solution
Posted (edited)

So in scouring for more info I found a solution:

migGroupFromTable = migGroupsToActivate[1]
nextMigGroup = Group.getByName(migGroupFromTable)
nextMigGroup:activate()                          

That does what I want, grabs a value from a table, and activates the group with that name.

But I still don't understand why the general structure of:

trigger.action.activateGroup("groupName")

--or

trigger.action.activateGroup(stringVariable)     -- where stringVariable == "groupName"

doesn't do basically the same thing.    I'll look into it some more, because if     trigger.action.activateGroup(Group)   actually wants the group mission ID number, or the GUID number of the group and not the name,  then I'm doing my most frequent ME script bug of wrong format of input into a function.   I probably also need to go back and look up the difference between . and : in LUA, which I looked up two days ago and have already forgotten.   Something about functions that pass self as the first parameter I think.   I'll update if I manage to un-confuse myself.

 

I managed to get it to work with this

--Modifying it again, trying trigger.action:

trigger.action.outText("testing activate method", 20, false)
migGroupFromTable = migGroupsToActivate[1]
trigger.action.outText(migGroupFromTable, 20, false)
nextMigGroup = Group.getByName(migGroupFromTable)
trigger.action.activateGroup(nextMigGroup)     
trigger.action.outText("Group getbyname got: " .. nextMigGroup, 20, false)

which throws and error on the final outText and I think reveals my problem.   trigger.action.activateGroup wants the Group object table, not the Group name string.  Using .getByName gets the right input, and with that it works.

Edited by esb77
Figured it out.

Callsign "Auger". It could mean to predict the future or a tool for boring large holes.

 

I combine the two by predictably boring large holes in the ground with my plane.

  • Recently Browsing   0 members

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