Forum Jump :

Author Message


Posts: 3
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name:

 
#1 Posted at 2016-12-06 21:01        
     
Hello I have searched but I have not found a solution.

I am trying to check if the current thing is the last thing in the array. I have tried:

if(_currThing == (count _array - 1)) then{ ...do something...};

However that throws a general error, so my syntax is wrong somewhere. Thanks very much for taking a look.

Added 28 minutes later:

Ok Solved.

The problem was I was comparing the wrong variable to the count.

Added 1 hour 5 minutes later:

Here is the working complete script for the never ending random patrol:

//Spawn points/ waypoints
_waypoints = ["wp1", "wp2", "wp3", "wp4"];

//start position of the spawned units

_startpoint = _waypoints call BIS_fnc_selectRandom;

//create and spawn group or unit

_mygroup = [getmarkerPos _startpoint, EAST, ["O_Soldier_TL_F", "O_Soldier_F"], [], [], [], [], [], 140]call BIS_fnc_spawnGroup;



//generate patrol path for mygroup

_fnc_randomPatrol = {

	for "_i" from 1 to (count _waypoints) do{
	
		_randomwaypoint = _waypoints call BIS_fnc_selectRandom;
		
		_currWp = _mygroup addWaypoint[getMarkerPos _randomwaypoint, 0];
			_currWp setWaypointType "MOVE";
			_currWp setWaypointBehaviour "SAFE";
			_currWp setWaypointSpeed "LIMITED";
			
		if(_i == (count _waypoints) - 1) then{
		
			//recursion
		
			_nul = [] call _fnc_randomPatrol;
		};
		
	};
	
};

//call the function

_fncCall = [] call _fnc_randomPatrol;

This post was edited by ghandolhagen (2016-12-07 07:56, ago)


Author Message


Posts: 1189
Rank:


Level: Member

Country: tr
Location:
Occupation: Computer Science student
Age: 22
In-game name: Wak

 
#2 Posted at 2016-12-07 11:22        
     
Glad you got it figured out yourself. One thing I'd like to mention is that you can use the selectRandom command instead of the old function. The command works faster, and it's easier to see what it's doing.

Sometimes I like to think as I started the whole "earplugs" thing.

W0lle: The only advice I can give you is: Do not try to understand BI. You will not succeed and it only makes your brain go boom. I would even go so far and say that not even they understand their own actions :-D.

#define getDamage getDammage

Advertisement


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 60
In-game name: Kobayashi Maru

 
#3 Posted at 2016-12-07 16:04        
     
You should avoid calling a function inside the same function.
And the main problem is that you're creating infinite waypoints before first of them is completed!
Not saying you can have up to 4 times the same waypoint in a call.

Make a real loop and wait for each path completed before adding new waypoints!

something like:

while {count units _mygroup >0} do {
  _newPath = _waypoints call bis_fnc_arrayShuffle;
  for "_i" from 1 to (count _waypoints) do{
    _randomwaypoint = _newpath deleteAt 0;
    _currWp = _mygroup addWaypoint[getMarkerPos _randomwaypoint, 0];
    _currWp setWaypointType "MOVE";
    _currWp setWaypointBehaviour "SAFE";
    _currWp setWaypointSpeed "LIMITED";
  };
  waitUntil {sleep 2; {alive _x} count units _mygroup == 0 or currentWaypoint _mygroup == count _waypoints};
  while {(count (waypoints _mygroup)) > 0} do {
    deleteWaypoint ((waypoints _mygroup) select 0)
  };
};

This post was edited by Pierre MGI (2016-12-07 16:35, ago)

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Author Message


Posts: 3
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name:

 
#4 Posted at 2016-12-08 06:06        
     
Hi Pierre. Thanks for the tip.
EDIT: I am curious as to why my system doesn't crash even though they are infinite?
I don't think it is infinite since I check for the last element and then the function calls itself again and populates a number of waypoints only equal to length of the waypoints array. But you are correct in that it generates them all at once. I haven't had any performance issues using this yet. Even when looping it 20 times from a trigger to generate 20 groups that then walk around "seemingly" endlessly.

I should mention that this is a single player mission. Perhaps I would be screwed if I attempted this in multiplayer :P The reason why I used recursion is that it is fairly common technique in programming and I didn't know how to do it in the Arma code syntax since I am fairly new to scripting for arma. Thanks again for the tip i will try it out :D.

Added 8 minutes later:

# 654wak654 : Glad you got it figured out yourself. One thing I'd like to mention is that you can use the selectRandom command instead of the old function. The command works faster, and it's easier to see what it's doing.

Thanks for that! I didn't know about it :D

This post was edited by ghandolhagen (2016-12-08 06:24, ago)


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 60
In-game name: Kobayashi Maru

 
#5 Posted at 2016-12-08 21:09        
     
# ghandolhagen : Hi Pierre. Thanks for the tip.

indeed!

# ghandolhagen : EDIT: I am curious as to why my system doesn't crash even though they are infinite?

I'm not as skilled as you in this domain, but one sure thing, you confuse the amount of added waypoints and the loop limit. Just because the waypoints completed or not, remain indefinitely until being erased. So, you're running after an inflating count! Furthermore, as there is no possible pause (sleep or waitUntil), your waypoints' list grows up drastically each second!

Test that:
Edit a group (not spawned, that's not the matter here).
Make the last unit as player (to see how the group reacts. If you're leader, nothing move of course).
Allow enhanced map info (in difficulty settings), just to see waypoints in map,
but don't forget to test the number of waypoints of the group: in debug console, "watch" for:
count waypoints yourgroupname
the name of your group must be a global variable for the console.
ENJOY!

One sure thing, I test my code before writing here, very most of the time. So, I can affirm there is no extra lines in mine and it's working "seamlessly". Perhaps, yours benefits of a permissive CPU capacity, but that's all.

This post was edited by Pierre MGI (2016-12-08 21:30, ago)

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Author Message


Posts: 3
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name:

 
#6 Posted at 2016-12-09 05:37        
     
Pierre

Thanks again for all the info! I love learning new stuff! :D