Jump to content
Sign in to follow this  
trex

Fail to pass a Group as an argument to execVM a sqf Script

Recommended Posts

Hi,

here is what i want to do : call a reinforcement script when a given unit die.

here is what i did on a dumb test mission to work this out :

i place 1 unit, myself and a distant group, that said reinforcement.

4ecac018-149b-4cee-9bce-1f83b798973b.jpg

As you can see I add :

ReinGrp = group this;

in the squad leader of the reinforcement group init field, which give me a global variable to address his group.

And then on my single enemy rifleman call this reinforcement group via this line on his init field :

null = [this, ReinGrp] execVM "reinforcement.sqf";

Note : I don't use the eventHandler on "killed" event yet, till i figure out my issue (presented bellow)

Finally here is the code of reinforcement.sqf :

_pos = position (_this select 0);
_ReGrp = (_this select 1);
hint format["TEST 1 : %1", _ReGrp]; // In Game show : TEST 1 : ANY
hint format["TEST 1 : %1", ReinGrp]; // In Game show : TEST 1 : 0 - 1-2 ALPHA
wp1 = _ReGrp addWaypoint [_pos, 10]; // nothing happen, group stay static, DONT WORK
// wp1 = ReinGrp addWaypoint [_pos, 10]; // This work ! But the purpose is to reuse this code by using parameter not global variable ...
wp1 setWaypointType "move";

As you can read on my commentary this script don't work, because it seems I don't get properly the 2nd argument of type Group. (hint command display the text "ANY")

Note that if I use the corresponding global variable of the group i want to work with, this work. (hint command display the proper text)

It seems strange because execVM can have anyType as argument, so in theory an array of an Object and and a Group should work, no ?

Thanks for any help on this, even if I feel bad that I committed a simple mistake that I'm not able to see it yet. :butbut:

Share this post


Link to post
Share on other sites

Hi, try to insert this in init of your single enemy rifleman:

null = this spawn {sleep 0.1; [_this, ReinGrp] execVM "reinforcement.sqf"};

Edited by DarkDruid
Typo fixed.

Share this post


Link to post
Share on other sites

Druid is most likely right. You need a small delay between assigning a variable and executing a script with that variable in it, because else it takes less than 0.1 secs to execute all of that. You could also just use ReinGrp in your script without assigning an extra variable.

Share this post


Link to post
Share on other sites

Problem seems to be that player unit's init is getting executed before the group's team leader unit init.

- The mission starts reading mission.sqm file

- Player init (null = [this, ReinGrp] execVM "reinforcement.sqf"; ) gets executed, but at this point, ReinGrp is NULL.

- Group team leader's init gets executed and assigns it's group to ReinGrp.

This could be fixed by either deleting the player unit (and save mission) and place it again (and save mission) so it's entry in mission.sqm is after the group leader unit or having some kind of delay like DarkDruid said.

Edited by neokika

Share this post


Link to post
Share on other sites

Thanks all of you for the replies !

Actually it is what I came up this nigh (sleeping is very instructive ;) ), the mission generation process is iterative so because my rifleman is created before the reinforcement squad, the global variable ReinGrp is not yet "created". I think it is working inside the script due to threading parallelism (the squad is created meanwhile the script is executed, especially I suspect hint command execution to take enough time to allow ReinGrp global variable to be assigned before its use on the following code)

Problem seems to be that player unit's init is getting executed before the group's team leader unit init.

- The mission starts reading mission.sqm file

- Player init (null = [this, ReinGrp] execVM "reinforcement.sqf"; ) gets executed, but at this point, ReinGrp is NULL.

- Group team leader's init gets executed and assigns it's group to ReinGrp.

This could be fixed by either deleting the player unit (and save mission) and place it again (and save mission) so it's entry in mission.sqm is after the group leader unit or having some kind of delay like DarkDruid said.

Yeah, not tested yet (will do soon) but I think that or the other will work.

Even though I think I'll prefer to address this inside a init.sqf script instead of the init line parameter of the unit/group, because It will prevent either adding several sleep command (save time is always good) or rebuild my mission by deleting and recreating several unit/group whose order of creation may become soon or later a puzzle resulting in severe headache. :386:

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×