Jump to content
Spriterfight

HELP problem with waitUntil returns nil

Recommended Posts

_grp = _this select 0;
_grp allowFleeing 0;
_units1 = units _grp;


{
_x addEventHandler ["Fired", {
	params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"];

_unit = _this select 0;
_ubitcount = (count (units group _unit));
_reloadcheck = {needReload _x == 1} count _units1 = unit _grp;
;

waitUntil {{needReload _x == 1} count _unitcount == 2};


}];
} forEach _units1;

I have this code and the waituntil returns nil or unexppected behaviour.The script is called via execVM in the group is init.I want the sxript to waitauntil every unit from a group fired its ammunition from the loaded magazine

Share this post


Link to post
Share on other sites

waitUntil has to be spawned, not called. Just wrap it in a spawned scope and it might fix it.

 

Also, instead of a fired EH, just spawn this code:

 

 

[_grp,_units1]spawn{

params["_grp","_units1"];

 

waitUntil{(_units1 select{ammo _x==0})isEqualTo _units1};

 

hint"We aint gotz no bullets, boss!";

};

Share this post


Link to post
Share on other sites
4 minutes ago, phronk said:

waitUntil has to be spawned, not called. Just wrap it in a spawned scope and it might fix it.

 

Also, instead of a fired EH, just spawn this code:

 

 

[_grp,_units1]spawn{

params["_grp","_units1"];

 

waitUntil{(_units1 select{ammo _x==0})isEqualTo _units1};

 

hint"We aint gotz no bullets, boss!";

};

The fired EH is important for the script.

Share this post


Link to post
Share on other sites

Spawning a waitUntil in a Fired EH will create a new loop for every shot fired which will destroy FPS and eventually crash the game. Change the waitUntil inside your fired EH to:

 

 

if((ammo(_this#0)==0)then{

 

_units1=units(group(_this#0));

_grp=group(_this#0);

 

 

if(_units1 select{ammo _x==0})isEqualTo _units1)then{

hint"Everyone is outta shootie things";};

};

Share this post


Link to post
Share on other sites
17 hours ago, Spriterfight said:

_ubitcount

Spelling mistake.

 

17 hours ago, Spriterfight said:

_reloadcheck = {needReload _x == 1} count _units1 = unit _grp;

_units1 is undefined inside the EH.

 

17 hours ago, Spriterfight said:

count _units1 = unit _grp;

Should be == comparison. unit is not a command. _grp is undefined inside EH

 

17 hours ago, Spriterfight said:

waitUntil {{needReload _x == 1} count _unitcount == 2};

You cannot wait inside an EH as the code is unscheduled.

 

  • Like 2

Share this post


Link to post
Share on other sites

@Spriterfight,
Edited as per Larrow's suggestions,
 

Spoiler

_grp = _this select 0;
_grp allowFleeing 0;

{
_x addEventHandler ["Fired", {
	params ["_unit"];

_unit = _this select 0;
_grp = group (_this select 0);
_unitcount = (count (units _grp));
_reloadcheck = {needReload _x == 1} count _units1 == unit _grp;

[_reloadCheck, _unitCount] spawn {
		waitUntil {sleep 1; {(_this select 0) _x == 1} count (_this select 1) == 2};
		};
	}];
} forEach units _grp;

still untested.

Have fun!

Share this post


Link to post
Share on other sites
1 hour ago, wogz187 said:

@Spriterfight,
Edited as per Larrow's suggestions,
 

  Reveal hidden contents


_grp = _this select 0;
_grp allowFleeing 0;

{
_x addEventHandler ["Fired", {
	params ["_unit"];

_unit = _this select 0;
_grp = group (_this select 0);
_unitcount = (count (units _grp));
_reloadcheck = {needReload _x == 1} count _units1 == unit _grp;

[_reloadCheck, _unitCount] spawn {
		waitUntil {sleep 1; {(_this select 0) _x == 1} count (_this select 1) == 2};
		};
	}];
} forEach units _grp;

still untested.

Have fun!

Hi it works.BTW  i have another problem the trigger wont work with this code 

({alive _x} count units t1) == ({_x in thisList} count units t1)

it only works if i kill the groupmembers  i dont know what is the problem with the trigger 

Share this post


Link to post
Share on other sites

Really the OP needs to be specific on what they are trying to accomplish.

Lets say there are two AI in the group, each only having one 30 round mag, By the time the last bullet is fired from any one of the units, you would end up with 60 scheduled threads being held open( waitUntil ). One for each time they fired a round.

 

Also when does a unit get flagged as neededReload? Immediately as the last round is fired? If not then all the threads are going to remain open, indefinitely. All depends on what the 2 is? the number of units in the group or just 2 out of a number of units in the whole group.

  • Like 1

Share this post


Link to post
Share on other sites
11 minutes ago, Larrow said:

Really the OP needs to be specific on what they are trying to accomplish.

Lets say there are two AI in the group, each only having one 30 round mag, By the time the last bullet is fired from any one of the units, you would end up with 60 scheduled threads being held open( waitUtil ). One for each time they fired a round.

 

Also when does a unit get flagged as neededReload? Immediately as the last round is fired? If not then all the threads are going to remain open, indefinitely. All depends on what the 2 is? the number of units in the group or just 2 out of a number of units in the whole group.

Hi. This is separate from the main topic.My triggers wont work if i set them on none.I am concerned that the game is broken but do the triggers have to set on something like blufor or opfor to activate like if my player is t1 and i set the trigger to detect if the player is in the triggerarea. with t1 in this List but my trigger wont activate if its set on none but if i set it on blufor it activates.Why?

 

Share this post


Link to post
Share on other sites
1 hour ago, Spriterfight said:

I am concerned that the game is broken

 

Which is more likely, that the RV engine or SQF is broken, or that you are doing something wrong?

Share this post


Link to post
Share on other sites
4 minutes ago, Harzach said:

 

Which is more likely, that the RV engine or SQF is broken, or that you are doing something wrong?

Umm i used profilenamespace but nothing more that changes something in the files.But such a simple condition like player in thisList; dosen't activates the trigger.I have never had such an experience with arma.Yesterday i was working on a script and i discovered that when my units had not activated the trigger when they were in the trigger area.

Share this post


Link to post
Share on other sites

You are leaving out so much information it's difficult to know where to start. Create a simple repro mission and share it.

  • Like 1

Share this post


Link to post
Share on other sites

@Spriterfight,

Quote

I wrote hint "work"; in the activation field

You did. I noticed that. It didn't "work" though. We knew it wouldn't work  because there is no activation for the trigger. Technically the trigger is working exactly as it's supposed to.

Share this post


Link to post
Share on other sites

So what i have to do to work as intended?what i have to change?

Btw so the hint didnt show up for you?

 

Share this post


Link to post
Share on other sites

@Spriterfight,

Quote

So what i have to do to work as intended?what i have to change?

We still don't know what the intended usage is. But to make that trigger work you need to change the Activation field to something either than "none". Then, in the Condition field start with: this

Have fun!

Share this post


Link to post
Share on other sites
7 minutes ago, Spriterfight said:

So what i have to do to work as intended?what i have to change?

 

Yesterday i was working on a mission where the trigger executes a script on a group if the group members are in the trigger area but i noticed when all of them entered nothing happened

Share this post


Link to post
Share on other sites

5 minutes ago, Spriterfight said:

Yesterday i was working on a mission where the trigger executes a script on a group if the group members are in the trigger area but i noticed when all of them entered nothing happened

I changed on activation hint "works"; player setDamage 1; and if i set the activation to blufor the trigger works but if i chage it to none it dosent.However on the other script it works with none.Why i have to chage it to blufor?Dosent it should work on none because i set the activaiton in the condiiton what is player in thisList

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

×