Jump to content
Luft08

[SOLVED] Recursive Script Questions

Recommended Posts


I'm fairly new to Arma 3 coding so I don't have a good understanding of how it handles scripts, variables, etc.

I wrote a small script that builds a marker name based on a random number. It then creates a waypoint at the position of the marker and based on a parameter passed in assigns the waypoint to a vehicle. 

I wanted to use the code to make the vehicle patrol an area with exact waypoint locations.

My question is: Can I safely call the script recursively by defining "on activation" code or am I sucking around for a buffer overflow? The code seems to work but if I created a memory leak it could take some time before it blows up.

Here is my code:

if (isServer) then {
	_destinationNumber = round(random 50) + 1;
	vehicleStr = _this select 0;
	_current_waypoint = "patrol_marker_"+str(_destinationNumber);
	_marker_pos = getMarkerPos _current_waypoint;
	deleteWaypoint [group vehicleStr, 0];
	_wp = group vehicleStr addWaypoint [_marker_pos, 0];
	_wp setWaypointType "MOVE";
	_wp setWaypointStatements ["true", "[vehicleStr] execVM 'chooseWaypoint.sqf';"];
};

 

Share this post


Link to post
Share on other sites

this is not really recursive because not the script starts the script again but the waypoint will start it if the waypoint gets activated. the prior script instance should have ended long before.

no problems here i guess

Share this post


Link to post
Share on other sites

Thanks, this is what I needed to know.  I was unsure if the code would end when the "ON ACT" fired or if it would wait until that completed.

 

BTW I would like to mark this as solved but I don't know how. (yeah, I'm a newbee.)

Share this post


Link to post
Share on other sites
10 hours ago, Luft08 said:

Thanks, this is what I needed to know.  I was unsure if the code would end when the "ON ACT" fired or if it would wait until that completed.

 

BTW I would like to mark this as solved but I don't know how. (yeah, I'm a newbee.)

 

Your code will finish when the waypoint has been created. It will run again when the vehicle has reached the waypoint. 

 

There's no inbuilt feature for marking as solved. Just edit the first post and thread title and add something like [SOLVED] at the beginning. 

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

×