Jump to content

Recommended Posts

Posted (edited)

Spent all night coming to the conclusion that Moose's SpawnScheduled() does not return an object and furthermore, it's not possible to find a group object spawned that way. At least that's what the mission and code are telling me.

 

All I wanted to do was spawn come vehicles in a way that would keep them spawning after they're destroyed and trigger some actions when they enter a zone. Can't believe I'm actually creating a new thread around this, but damn, it doesn't work. Simple as that. Here is my A/B test mission. Test Driver 2 smokes red and that is it. Not going to work for me. Can't even find the group after it's spawned.

 

ZoneA = ZONE:New("Zone A")

Driver_1_Spawn = SPAWN:New("Test Driver 1"):InitLimit(1, 0)
Driver_1 = Driver_1_Spawn:SpawnScheduled(1,0)

Driver_2_Spawn = SPAWN:New("Test Driver 2"):InitLimit(1, 0)
Driver_2 = Driver_2_Spawn:Spawn()

-- Test Driver 1

SCHEDULER:New(nil,
 function()
   if Driver_1:IsCompletelyInZone(ZoneA) then
     Driver_1:SmokeRed()
   end
 end, 
{}, 0, 2)

SCHEDULER:New(nil,
 function()
   if GROUP:FindByName("Test Driver 1"):IsCompletelyInZone(ZoneA) then
     GROUP:FindByName("Test Driver 1"):SmokeBlue()
   end
 end, 
{}, 1, 2)

SCHEDULER:New(nil,
 function()
   if Group.getByName("Test Driver 1"):IsCompletelyInZone(ZoneA) then
     Group.getByName("Test Driver 1"):SmokeGreen()
   end
 end, 
{}, 1, 2)

-- Test Driver 2

SCHEDULER:New(nil,
 function()
   if Driver_2:IsCompletelyInZone(ZoneA) then
     Driver_2:SmokeRed()
   end
 end, 
{}, 0, 2)

SCHEDULER:New(nil,
 function()
   if GROUP:FindByName("Test Driver 2"):IsCompletelyInZone(ZoneA) then
     GROUP:FindByName("Test Driver 2"):SmokeBlue()
   end
 end, 
{}, 1, 2)

 

Can someone please look at this code or the attached test mission and explain this to me? I'm done fighting it.

 

Thanks

TEST.lua

TEST.miz

Edited by rassy7
Meant Test Driver 2 smokes red, not 1. Corrected.

The State Military (MAG 13)

 

[sIGPIC][/sIGPIC]



 

SHEEP WE-01

AV-8B BuNo 164553

VMA-214

Col J. “Poe” Rasmussen

http://www.statelyfe.com

 

Specs: Gigabyte Z390 Pro Wifi; i9-9900K; EVGA 2080 Ti Black; 32GB Corsair Vengeance LPX DDR4; Samsung 970 EVO Series M.2 SSD; WIN10; ASUS VG248QE; CV-1 and Index



Modules: A-10C; AV8B; CA; FC3; F-5; F-14; F-18; F-86; HAWK; L-39; P-51; UH1H; NTTR; Normandy; Persian Gulf

Posted

Ok, thank you Delta. This is helpful and will fix my issue. I just wish it was weaved in more closely with the spawning documentation so I could have discovered it the easy way.

 

Thanks again.

The State Military (MAG 13)

 

[sIGPIC][/sIGPIC]



 

SHEEP WE-01

AV-8B BuNo 164553

VMA-214

Col J. “Poe” Rasmussen

http://www.statelyfe.com

 

Specs: Gigabyte Z390 Pro Wifi; i9-9900K; EVGA 2080 Ti Black; 32GB Corsair Vengeance LPX DDR4; Samsung 970 EVO Series M.2 SSD; WIN10; ASUS VG248QE; CV-1 and Index



Modules: A-10C; AV8B; CA; FC3; F-5; F-14; F-18; F-86; HAWK; L-39; P-51; UH1H; NTTR; Normandy; Persian Gulf

Posted
Ok, thank you Delta. This is helpful and will fix my issue. I just wish it was weaved in more closely with the spawning documentation so I could have discovered it the easy way.

 

Thanks again.

 

Yes, this should be a super main thing heavily bolded and pointed out in the documentation cause it is something that causes just about everyone to have issues with. It is in the documentation but sort of just briefly mentioned.

  • Thanks 1
Posted

If it helps others who stumble upon this thread, here's some supporting information I found:

 

Catch the Group Spawn Event in a callback function!

When using the SPAWN.SpawnScheduleds are created following the spawn time interval parameters. When a new Group is spawned, you maybe want to execute actions with that group spawned at the spawn event. The SPAWN class supports this functionality through the method SPAWN.OnSpawnGroup( *function( SpawnedGroup ) end * ), which takes a function as a parameter that you can define locally. Whenever a new Group is spawned, the given function is called, and the Group that was just spawned, is given as a parameter. As a result, your spawn event handling function requires one parameter to be declared, which will contain the spawned Group object. A coding example is provided at the description of the SPAWN.OnSpawnGroup( *function( SpawnedGroup ) end * ) method.

 

From the spawn class page

 

This thread also shows some beneficial examples.

 

Couple examples in FC's code here too.

  • Thanks 1

The State Military (MAG 13)

 

[sIGPIC][/sIGPIC]



 

SHEEP WE-01

AV-8B BuNo 164553

VMA-214

Col J. “Poe” Rasmussen

http://www.statelyfe.com

 

Specs: Gigabyte Z390 Pro Wifi; i9-9900K; EVGA 2080 Ti Black; 32GB Corsair Vengeance LPX DDR4; Samsung 970 EVO Series M.2 SSD; WIN10; ASUS VG248QE; CV-1 and Index



Modules: A-10C; AV8B; CA; FC3; F-5; F-14; F-18; F-86; HAWK; L-39; P-51; UH1H; NTTR; Normandy; Persian Gulf

Posted
You need to use the OnSpawnGroup method of SPAWN ...

 

Delta, thanks for this tip. I was able to capture the groups and do what I ultimately hoped to do, add them to a table over which I could later iterate with a loop.

 

It works for most things, but I can't seem to make setting a command work. I can't just use the table index and I'm not sure how to get the group name from whatever I added to the table.

 

Here's a simple test example of what I'm trying to do. Am I close? Can this work?

 

ZoneA = ZONE:New("Zone A") -- Debug

enemyGroup_1 = GROUP:FindByName("enemyGroup1")
enemyGroup_2 = GROUP:FindByName("enemyGroup2")
enemyGroup_3 = GROUP:FindByName("enemyGroup3")

testDriversTable = {}

test_Car_1_Spawn = SPAWN:New("Driver 1")
 :InitLimit(1, 0)
 :OnSpawnGroup(
   function(SpawnGroup)
     testDriversTable[1] = SpawnGroup
   end
 )
 :SpawnScheduled(1,0)

test_Car_2_Spawn = SPAWN:New("Driver 2")
 :InitLimit(1, 0)
 :OnSpawnGroup(
   function(SpawnGroup)
     testDriversTable[2] = SpawnGroup
   end
 )
 :SpawnScheduled(1,0)

test_Car_3_Spawn = SPAWN:New("Driver 3")
 :InitLimit(1, 0)
 :OnSpawnGroup(
   function(SpawnGroup)
     testDriversTable[3] = SpawnGroup
   end
 )
 :SpawnScheduled(1,0)
 
SCHEDULER:New(nil,
 function()
   for i = 1, #testDriversTable do
     if testDriversTable[i]:IsCompletelyInZone(ZoneA) then
       enemyGroup_1:OptionROEWeaponFree()
       enemyGroup_2:OptionROEWeaponFree()
       enemyGroup_3:OptionROEWeaponFree()

-- TROUBLE SPOT

-- Not sure how to get correct group in loop
       local con = [color="Red"]Group.getByName("whatever")[/color]:getController()
       con:setCommand({id = 'SetInvisible', params = {value = true}})

-- This doesn't work
      [color="red"] testDriversTable[i][/color]:getController():setCommand({id = 'SetInvisible', params = {value = false}})

-- This doesn't work either
       [color="red"]testDriversTable[i][/color]:GetName():getController():setCommand({id = 'SetInvisible', params = {value = false}})
     end
   end
 end,
{}, 0, 5)

 

Thank you!

TEST.miz

TEST.lua

The State Military (MAG 13)

 

[sIGPIC][/sIGPIC]



 

SHEEP WE-01

AV-8B BuNo 164553

VMA-214

Col J. “Poe” Rasmussen

http://www.statelyfe.com

 

Specs: Gigabyte Z390 Pro Wifi; i9-9900K; EVGA 2080 Ti Black; 32GB Corsair Vengeance LPX DDR4; Samsung 970 EVO Series M.2 SSD; WIN10; ASUS VG248QE; CV-1 and Index



Modules: A-10C; AV8B; CA; FC3; F-5; F-14; F-18; F-86; HAWK; L-39; P-51; UH1H; NTTR; Normandy; Persian Gulf

Posted

Slight branch to this topic, as I also recently spent several hours puzzling over initiating a set of events that was easily handled with

 

 

 

SPAWN:OnSpawnGroup(SpawnCallBackFunction, SpawnFunctionArguments, ...)

 

 

I am interested in the utility of "Arguments" provided in this and many other MOOSE methods. MOOSE documentation has precious few examples of good use of method arguments and I have precious little coding experience. Can anyone illuminate how arguments might prove useful in the :OnSpawnGroup (or any other illustrative) method?

Posted (edited)
Can anyone illuminate how arguments might prove useful in the :OnSpawnGroup (or any other illustrative) method?

 

Hi there Habu!

 

As it happens, I also struggled with this problem for the last couple of days, and Delta helped me out over the MOOSE Discord channel.

 

I just discovered the :OnSpawnGroup method yesterday (because Delta mentioned it), but I think I can provide an example where an argument is crucial for a function to do its job properly.

 

Here you have an example of the script that solved my problems.

 

The argument is given in line 10 and it's required in line 12, I think it's necessary for the last "subfunction" to actually do its job.

 

Hope this helps.

Edited by Hardcard
Posted (edited)

TX. OK, I see. Seems you used function:

 

function MyPlane:OnEventCrash()
 SpawnGroup:Destroy(true)
end

as the argument (?), but why no comma separating the argument function, per the documentation? Is the subfunction really an argument? I need to think about this to wrap my head around it. Many of the methods also have specific limitations for their arguments that are unclear to me. This helps, tho.

Edited by Habu_69
Clarification.
Posted (edited)
TX. OK, I see. Seems you used function:

 

function MyPlane:OnEventCrash()
 SpawnGroup:Destroy(true)
end

as the argument (?), but why no comma separating the argument function, per the documentation? Is the subfunction really an argument?.

 

Nope, I don't think that function acted like an argument.

The argument was SpawnGroup, first introduced between brackets, line 10.

 

Let's paste the documentation model here, so we're on the same page:

SPAWN:OnSpawnGroup(SpawnCallBackFunction, SpawnFunctionArguments, ...)

 

Yes...now I see how those commas can be misleading :megalol:

 

Check the script again.

 

Actually, let me write the :OnSpawnGroup bit in a single line too, see if it's clearer that way...

 

SPAWN:OnSpawnGroup(function( SpawnGroup --THIS IS THE ARGUMENT--)functionMyPlane:OnEventCrash()SpawnGroup:Destroy(true)end end)

 

The way I see it, you must forget about the first and last parenthesis, ok?

Act as if they weren't there at all.

If you do that, you'll see quite clearly that this is a typical function layout.

Namely:

function(argument) --sub--function OnEventCrash --do subfunction stuff-- end end

 

The confusing bit is that it's all inside a huge parenthesis, and the documentation can be quite misleading. I don't think any of those SpawnFunctionArguments are given in my script, it's just a huge SpawnCallBackFunction(which has a subfunction in it) between brackets, that's why there are no commas.

 

Again, I could be 100% wrong in my assumptions, but, to be honest, the function example in the MOOSE documentation makes no sense to me otherwise...

It just looks like a SpawnCallBackFunction between brackets, without any SpawnFunctionArguments given.

 

Basically, it's as if the actual model were:

SPAWN:OnSpawnGroup(SpawnCallBackFunction)

Edited by Hardcard
Posted (edited)

Yeah, see, I thought that the function(SpawnGroup) was the SpawnCallBackFunction and an ARGUMENT would be some other variable/parameter/value. Your presentation means documentation is quite confusing.

 

 

Light bulb slowly starting to glow. So, I guess

 , SpawnFunctionArguments 

are actual arguments of the SpawnCallBackFunction, NOT some other arguments relating to the :OnSpawnGroup.

Edited by Habu_69
Posted (edited)

I'm also quite clueless about arguments and parameters, to be honest.

 

In any case, seems like the confusion is dispelled by simply forgetting about those SpawnFunctionArguments.

 

For practical purposes, simply consider the model to be:

SPAWN:OnSpawnGroup( SpawnCallBackFunction(SpawnGroup) )

 

The method should work (as long as SpawnGroup is passed as an argument/parameter of the SpawnCallBackFunction).

Edited by Hardcard
Posted

Yeah, I have been using MOOSE for a few months, now, ignoring the "optional arguments" documented in the methods. Never found another use for arguments, except as relates to the functions themselves, of course. Anyway, thanks for discussion. Unless someone else chimes in, I will assume the concept is as we have described it.

Posted
Delta, thanks for this tip. I was able to capture the groups and do what I ultimately hoped to do, add them to a table over which I could later iterate with a loop.

 

It works for most things, but I can't seem to make setting a command work. I can't just use the table index and I'm not sure how to get the group name from whatever I added to the table.

 

Here's a simple test example of what I'm trying to do. Am I close? Can this work?

 

ZoneA = ZONE:New("Zone A") -- Debug

enemyGroup_1 = GROUP:FindByName("enemyGroup1")
enemyGroup_2 = GROUP:FindByName("enemyGroup2")
enemyGroup_3 = GROUP:FindByName("enemyGroup3")

testDriversTable = {}

test_Car_1_Spawn = SPAWN:New("Driver 1")
 :InitLimit(1, 0)
 :OnSpawnGroup(
   function(SpawnGroup)
     testDriversTable[1] = SpawnGroup
   end
 )
 :SpawnScheduled(1,0)

test_Car_2_Spawn = SPAWN:New("Driver 2")
 :InitLimit(1, 0)
 :OnSpawnGroup(
   function(SpawnGroup)
     testDriversTable[2] = SpawnGroup
   end
 )
 :SpawnScheduled(1,0)

test_Car_3_Spawn = SPAWN:New("Driver 3")
 :InitLimit(1, 0)
 :OnSpawnGroup(
   function(SpawnGroup)
     testDriversTable[3] = SpawnGroup
   end
 )
 :SpawnScheduled(1,0)
 
SCHEDULER:New(nil,
 function()
   for i = 1, #testDriversTable do
     if testDriversTable[i]:IsCompletelyInZone(ZoneA) then
       enemyGroup_1:OptionROEWeaponFree()
       enemyGroup_2:OptionROEWeaponFree()
       enemyGroup_3:OptionROEWeaponFree()

-- TROUBLE SPOT

-- Not sure how to get correct group in loop
       local con = [color="Red"]Group.getByName("whatever")[/color]:getController()
       con:setCommand({id = 'SetInvisible', params = {value = true}})

-- This doesn't work
      [color="red"] testDriversTable[i][/color]:getController():setCommand({id = 'SetInvisible', params = {value = false}})

-- This doesn't work either
       [color="red"]testDriversTable[i][/color]:GetName():getController():setCommand({id = 'SetInvisible', params = {value = false}})
     end
   end
 end,
{}, 0, 5)

 

Thank you!

 

I, too, had been stumped by arguments and like you, Habu, I had just been basically ignoring them. This is helpful

 

That said, I'm still wondering if anyone can help me with ^^^ this request. I can add group objects to a table with :OnSpawnGroup, but when I need to reference those objects again by name, I'm not sure how to do it. Referencing the table index isn't working. See the code/mission files in post #6. Trying to iterate through the table and change invisibility status for groups that meet an if statement.

 

Thanks!

The State Military (MAG 13)

 

[sIGPIC][/sIGPIC]



 

SHEEP WE-01

AV-8B BuNo 164553

VMA-214

Col J. “Poe” Rasmussen

http://www.statelyfe.com

 

Specs: Gigabyte Z390 Pro Wifi; i9-9900K; EVGA 2080 Ti Black; 32GB Corsair Vengeance LPX DDR4; Samsung 970 EVO Series M.2 SSD; WIN10; ASUS VG248QE; CV-1 and Index



Modules: A-10C; AV8B; CA; FC3; F-5; F-14; F-18; F-86; HAWK; L-39; P-51; UH1H; NTTR; Normandy; Persian Gulf

Posted

You can write your OnSpawnGroup function inline like the documentation but you can also have a reference to an actual function and define the function on its own just like any other function. You pass the parametes like the documentation says. It’s just a little difficult to see when things are inline.

 

I have examples and situations where I use parameters but I’m not at my gaming PC right now. If I remember in the next few days I will post something here.

 

Of the top of my head you can have something like this:

 

Function dosomething(SpawnGroup, firstparam, secondparam)
— SpawnGroup here would be the group spawned
— firstparam would be 1
— secondparam would be “two”
End

Spawn:New():OnSpawnGroup(dosomething, 1, “two”) ...

Posted (edited)

@Delta

Thanks Delta,

 

That definitely explains why the documentation model is written like that.

I'll be applying this technique in my scripts from now on!

 

@rassy7

 

Sorry mate, I don't know how to do that either, but, tbh, I'd also be interested in learning how to do that.

Handling group/unit tables is the next item in my "to learn" list.

Edited by Hardcard
  • Recently Browsing   0 members

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