Jump to content
Robustcolor

Fetch position from array and remove it

Recommended Posts

Hi, is it possible to fetch defined positions/markers from an array and then remove it from the array?

 

Example below, i've placed all the markers in the editor then into the Markerarray in the script.

 

Then spawn 1 to 10 Units and i want each unit to pick one of the Markers from the array and also remove it so next unit that being created don't spawn on the same Marker.

 

Is it possible?

Markerarray = ["1","2","3","4","5","6","7","8","9","10"];

for "_i" from 1 to 10 do{

private ["_grp1","_unit"];

_grp01 = createGroup [east, true];
_unit = _grp01 createUnit [selectRandom ["uns_men_VC_mainforce_AS1","uns_men_VC_mainforce_HMG"], Markerarray, [], 350, "FORM"];

};

 

Share this post


Link to post
Share on other sites
Markerarray = ["1","2","3","4","5","6","7","8","9","10"];

for "_i" from 0 to (count MarkerArray) do
{

private ["_grp","_unit"];

_grp = createGroup [east, true];
_unit = _grp createUnit [selectRandom ["uns_men_VC_mainforce_AS1","uns_men_VC_mainforce_HMG"],getMarkerPos (Markerarray select _i), [], 350, "FORM"];
Markerarray deleteAt _i;

};

try like this

Share this post


Link to post
Share on other sites

It's not even necessary to use the deleteAt in this case, this will spawn units at each marker, I'm guessing that's not exactly what you want.
 

Share this post


Link to post
Share on other sites

Something like this could do:

 

Markerarray = ["1","2","3","4","5","6","7","8","9","10"];
Markerarray = Markerarray call BIS_fnc_arrayShuffle;

for "_i" from 0 to 3 do{

private ["_grp01","_unit"];

_grp01 = createGroup [east, true];
_unit = _grp01 createUnit [selectRandom ["uns_men_VC_mainforce_AS1","uns_men_VC_mainforce_HMG"], getMarkerPos (Markerarray # _i), [], 350, "FORM"];

};

Note your typo in private which I corrected, simply shuffle the array and iterate through the shuffled marker array to spawn units on the randomized markers.

You also need to start the for loop at 0 for the first array index to work.

 

Cheers

Share this post


Link to post
Share on other sites

{createGroup [east, true] createUnit [selectRandom ["uns_men_VC_mainforce_AS1","uns_men_VC_mainforce_HMG"], getMarkerPos _x, [], 350, "FORM"]} forEach Markerarray;

  • Like 1

Share this post


Link to post
Share on other sites
On 12/15/2019 at 12:53 PM, killzone_kid said:

{createGroup [east, true] createUnit [selectRandom ["uns_men_VC_mainforce_AS1","uns_men_VC_mainforce_HMG"], getMarkerPos _x, [], 350, "FORM"]} forEach Markerarray;

How would it look like inside this? Get error.

Markerarray = ["1","2","3","4","5","6","7","8","9","10"];

Infantry = {
{
private _grp01 = createGroup [east, true];
private _unit = _grp01 createUnit [selectRandom ["uns_men_VC_mainforce_AS1","uns_men_VC_mainforce_HMG"], getMarkerPos _x, [], 350, "FORM"]
} forEach Markerarray; 

{_x setSkill 1;
_x setSkill ["AimingAccuracy",0.1];
_x allowFleeing 0;
} forEach (units _grp01);

_grp01 deleteGroupWhenEmpty true;
_grp01 EnableDynamicSimulation true;

{_x addCuratorEditableObjects [units _grp01, true];} forEach allCurators;

sleep 1;
};

What i can think of is something like this

{		

_x deleteGroupWhenEmpty true;

} forEach (allGroups select {side _x==east});

 

Share this post


Link to post
Share on other sites
Quote

_grp01 deleteGroupWhenEmpty true;


this makes no sense for 3 reasons
1. _grp01 is undefined in this scope
2. even if it was defined it would only be the last group created and not every group you created
3. you already create group with deleteWhenEmpty flag, why do you need to set it again?

Share this post


Link to post
Share on other sites
40 minutes ago, killzone_kid said:


this makes no sense for 3 reasons
1. _grp01 is undefined in this scope
2. even if it was defined it would only be the last group created and not every group you created
3. you already create group with deleteWhenEmpty flag, why do you need to set it again?

Ah,  that's not suppose to be there, i have it when i use bis spawn group not when createunit. accidentally added it here.

 

But i can't get foreach Markerarray to work inside my script.

Because only using this, i can't adjust skills, add it to zeus etc.

{createGroup [east, true] createUnit [selectRandom ["uns_men_VC_mainforce_AS1","uns_men_VC_mainforce_HMG"], getMarkerPos _x, [], 350, "FORM"]} forEach Markerarray; 

 

Share this post


Link to post
Share on other sites
22 hours ago, killzone_kid said:

2. even if it was defined it would only be the last group created and not every group you created

Are you sure? How would i add so each group has the deletegroup command?

example

for "_i" from 0 to 3 do {

private _grp01 = [_pos, west, [0,1,2,3,4] apply {selectRandom Regularinfantry},[],[],[1,1],[1,1],[]] call BIS_fnc_spawnGroup; 

_grp01 deleteGroupWhenEmpty true; <--- What should this be so each group deletegroup when empty?

};

 

Share this post


Link to post
Share on other sites
46 minutes ago, Robustcolor said:

Are you sure?

Am I sure if you assign to the same variable different values that the variable will contain only the last assigned value? Yeah, I am pretty damn sure

Share this post


Link to post
Share on other sites

So you're telling me that this _grp01 EnableDynamicSimulation true; will only affect last spawned unit? How can i make it affect them all?
 

Markerarray = ["1","2","3","4","5","6","7","8","9","10"];

{

private ["_grp01"];

_grp01 = createGroup [east,true];

_unit = _grp01 createUnit [selectRandom ["uns_men_VC_mainforce_AS1","uns_men_VC_mainforce_HMG"], getmarkerpos _x,[],0,"NONE"];
 
{_x setSkill 1;
_x setSkill ["AimingAccuracy",0.1];
_x allowFleeing 0;
} forEach (units _grp01);

_grp01 EnableDynamicSimulation true;

{_x addCuratorEditableObjects [units _grp01, true];} forEach allCurators;


} forEach Markerarray;

What i can think of is something like this

{
_x deleteGroupWhenEmpty true;
} forEach (allGroups select {side _x==east});

 

Share this post


Link to post
Share on other sites
21 hours ago, killzone_kid said:

Am I sure if you assign to the same variable different values that the variable will contain only the last assigned value? Yeah, I am pretty damn sure

Since we are talking about private variables in this topic, a private local variable is only visible in the script, or function, or Control Structures in which it was defined. So could you explain how the _grp01 EnableDynamicSimulation true; will only contain the last assigned value for only the last spawned group? Since i'm using private variable.

Share this post


Link to post
Share on other sites

This has nothing to do with privacy of the variable. You assign to any variable, the previous value it had gets replaced, so the value of the variable IS THE LAST VALUE YOU ASSIGNED TO IT

Share this post


Link to post
Share on other sites
15 minutes ago, killzone_kid said:

This has nothing to do with privacy of the variable. You assign to any variable, the previous value it had gets replaced, so the value of the variable IS THE LAST VALUE YOU ASSIGNED TO IT

I understand this but it feels out of context here.

 

If i have 5 scripts, functions or scopes the private variable inside it wont be overwritten in the other scripts. Or i have missunderstand something here? Because it sounds like when i read your text i can only have one defined variable once otherwise it will be overwritten if you use same variable outside of the script or scope.

Share this post


Link to post
Share on other sites

You are assigning to the same variable repeatedly in the loop which is your forEach loop, how is this out of context exactly?

Share this post


Link to post
Share on other sites
On 12/15/2019 at 5:24 PM, Robustcolor said:

So you're telling me that this _grp01 EnableDynamicSimulation true; will only affect last spawned unit? How can i make it affect them all?
 

Spoiler


Markerarray = ["1","2","3","4","5","6","7","8","9","10"];

{

	private ["_grp01"];

	_grp01 = createGroup [east,true];

	_unit = _grp01 createUnit [selectRandom ["uns_men_VC_mainforce_AS1","uns_men_VC_mainforce_HMG"], getmarkerpos _x,[],0,"NONE"];
	 
	{
		_x setSkill 1;
		_x setSkill ["AimingAccuracy",0.1];
		_x allowFleeing 0;
	}forEach (units _grp01);

	_grp01 EnableDynamicSimulation true;

	{_x addCuratorEditableObjects [units _grp01, true];} forEach allCurators;

} forEach Markerarray;

 

This is fine.

 

KK is talking about your original shown code where EnableDynamicSimulation was outside the foreach markerArray. So _grp01 was undefined at EnableDynamicSimulation due to _grp01 being private inside the foreach's scope.

Spoiler
On 12/15/2019 at 3:15 PM, Robustcolor said:


Markerarray = ["1","2","3","4","5","6","7","8","9","10"];

Infantry = {
  {
    //Create group _grp01 inside foreach
    private _grp01 = createGroup [east, true];
    private _unit = _grp01 createUnit [selectRandom ["uns_men_VC_mainforce_AS1","uns_men_VC_mainforce_HMG"], getMarkerPos _x, [], 350, "FORM"]
  } forEach Markerarray; 

  {_x setSkill 1;
  _x setSkill ["AimingAccuracy",0.1];
  _x allowFleeing 0;
  } forEach (units _grp01); //Group here is undefined

  _grp01 deleteGroupWhenEmpty true; //Group here is undefined
  _grp01 EnableDynamicSimulation true; //Group here is undefined

  {_x addCuratorEditableObjects [units _grp01, true];} forEach allCurators; //Group here is undefined

  sleep 1;
};

Undefined as _grp01 is private in foreach markerArray scope.

 

 

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

×