Jump to content
atomickrypton

Help With Choosing A Random Variable (BIS_fnc_selectRandom)

Recommended Posts

Hello BIS Forums,

 

I am working on a mission which involves a cool chase scene, and to put in a "randomness" factor, I have recorded 3 different paths the AI can take.

 

The paths work, but for some reason, the script I am using to choose the random path isn't really working.

 

Here it is:

_poi = _this select 0;

_randomMovement = ["pursuitPath1","pursuitPath2","pursuitPath3"]; 

_dataPath = _randomMovement call BIS_fnc_selectRandom;

hint format ["The path will be: %1",_dataPath];

sleep 0.5; // The script works up until here..

if (_dataPath == pursuitPath1) then 
{
	hint "good";
	_pursuit1 = [_poi] execVM "path\play.sqf"; // play, play3 and play4 are the files that make the AI follow the path, they all work when I execute them through the debug console or by trigger.
	waitUntil {scriptDone _pursuit1}; 
	terminate _pursuit1;
};

if (_dataPath == pursuitPath2) then 
{
	hint "bueno";
	_pursuit2 = [_poi] execVM "path\play3.sqf";
	waitUntil {scriptDone _pursuit2};
	terminate _pursuit2;
};

if (_dataPath == pursuitPath3) then 
{
	hint "gut";
	_pursuit3 = [_poi] execVM "path\play4.sqf";
	waitUntil {scriptDone _pursuit3};
	terminate _pursuit3;
};


I am still learning the basics and everything there is to scripting, so bear with me if I made a simple error.  I believe it has to do with the condition with the if statement, however, I am not sure what to do and google has failed me in this endeavor.

 

If there is any help you all can offer it will be greatly appreciated!

 

Thanks all : )

Share this post


Link to post
Share on other sites
_randomMovement = ["pursuitPath1","pursuitPath2","pursuitPath3"]; 

_dataPath = _randomMovement call BIS_fnc_selectRandom;


is the same as

_dataPath = ["pursuitPath1","pursuitPath2","pursuitPath3"] call BIS_fnc_selectRandom;

Bad syntax

_dataPath == pursuitPath1

should be

_dataPath == "pursuitPath1"

for each if

waitUntil {sleep 1; scriptDone _pursuit1};

use some sleep inside waituntil  if the whole code is running in scheduled environment otherwise it will be check the condition on eachframe ~60x/s

Share this post


Link to post
Share on other sites

Thanks for the reply!

 

I changed what you had suggested and it works beautifully.

 

Once again, thanks for your assistance and tips regarding syntax.

Share this post


Link to post
Share on other sites

You could boil all that down to just

_poi = _this select 0;

_dataPath = ["play","play3","play4"] call BIS_fnc_selectRandom;

hint format ["The path will be: %1",_dataPath];

sleep 0.5;

_pursuit = [_poi] execVM format[ "path\%1.sqf", _dataPath ];
waitUntil {scriptDone _pursuit};
If a script is done then there is no need to terminate it.

Share this post


Link to post
Share on other sites

 

You could boil all that down to just

_poi = _this select 0;

_dataPath = ["play","play3","play4"] call BIS_fnc_selectRandom;

hint format ["The path will be: %1",_dataPath];

sleep 0.5;

_pursuit = [_poi] execVM format[ "path\%1.sqf", _dataPath ];
waitUntil {scriptDone _pursuit};
If a script is done then there is no need to terminate it.

 

Here comes The Larrow. :D

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

×