Jump to content
Sign in to follow this  
[evo] dan

Struggling with array manipulation

Recommended Posts

I had a read over at Myke's beginners arrays and had a look at the array page on the biki. But I cannot seem to figure out how to get my scripts to take away.

Here is my aim with this script:

- Randomly select a mission, and then execute it (this part works)

- Then remove that mission from the array, so it cannot be activated again (this is where its going wrong)

Here are the 2 different ways I have tried to do this:

_ar1 = serverlogic getVariable ["missionlength", 0];	
_startingvalue = 0;
_nme = 1;
serverlogic setVariable ["mission_status", _startingvalue, TRUE];	

if(_ar1 == 1) then { //short missions
_myMissions = ["missions\template.sqf"]; //mission array. Put your missions that you want into this pool
_curMission = _myMissions select floor random count _myMissions; //this selects a mission from the array pool
[] execVM _curMission; //executes the chosen mission
   _newarray = [_curMission];
_myMissions = _myMissions - _newarray;
};

while(_nme == 1) do {
_ar2 = serverlogic getVariable ["mission_status", 0];
sleep 15;
if(_ar2 == 1) then {
	_curMission = _myMissions select floor random count _myMissions; //this selects a mission from the array pool
	[] execVM _curMission; //executes the chosen mission
	_newarray = [_curMission];
	_myMissions = _myMissions - _newarray;
	serverlogic setVariable ["mission_status", _startingvalue, TRUE];
	_curMission = 0;
};
sleep 60;
};

and

//init stuff
_ar1 = serverlogic getVariable ["missionlength", 0];	
_startingvalue = 0;
_nme = 1;
serverlogic setVariable ["mission_status", _startingvalue, TRUE];

//first selection
if(_ar1 == 1) then { //short missions
_myMissions = ["missions\template.sqf"]; //mission array. Put your missions that you want into this pool
_curMission = _myMissions select floor random count _myMissions; //this selects a mission from the array pool
[] execVM _curMission; //executes the chosen mission
_myMissions = _myMissions - _curMission; //takes mission from pool
_curMission = 0;
};

while(_nme == 1) do {
_ar2 = serverlogic getVariable ["mission_status", 0];
sleep 15;
if(_ar2 == 1) then {
	_curMission = _myMissions select floor random count _myMissions; //this selects a mission from the array pool
	[] execVM _curMission; //executes the chosen mission
	_myMissions = _myMissions - _curMission; //takes mission from pool
	serverlogic setVariable ["mission_status", _startingvalue, TRUE];
	_curMission = 0;
};
sleep 60;
};

Share this post


Link to post
Share on other sites
	_myMissions = _myMissions - [color="#FF0000"][[/color]_curMission[color="#FF0000"]][/color]; //takes mission from pool

Share this post


Link to post
Share on other sites

will that work within the 'if' statement?

edit:

I found the issue with it, and got it fixed. It was because I was rnadomly selecting the mission from another script at the same time.

Edited by [EVO] Dan

Share this post


Link to post
Share on other sites

Sure, but all I was pointing out is that you were missing the [ ] around _curMission when trying to subtract it. You were trying to subtract a string from an array instead of an array from an array.

Share this post


Link to post
Share on other sites

Ok, I changed the code to this:

//init stuff
_ar1 = serverlogic getVariable ["missionlength", 0];	
_startingvalue = 0;
_nme = 1;
serverlogic setVariable ["mission_status", _startingvalue, TRUE];	
_myMissions = ["missions\template.sqf","missions\mission1.sqf"]; //mission array. Put your missions that you want into this pool
//first selection
if(_ar1 == 1) then { //short missions

_curMission = _myMissions select floor random count _myMissions; //this selects a mission from the array pool
[] execVM _curMission; //executes the chosen mission
_myMissions = _myMissions - [_curMission]; 
};

while(_nme == 1) do {
_ar2 = serverlogic getVariable ["mission_status", 0];
sleep 15;
if(_ar2 == 1) then {
	_curMission = _myMissions select floor random count _myMissions; //this selects a mission from the array pool
	[] execVM _curMission; //executes the chosen mission
	_myMissions = _myMissions - [_curMission]; //takes mission from pool
	serverlogic setVariable ["mission_status", _startingvalue, TRUE];
	_curMission = 0;
};
sleep 60;
};

It spawns the first mission, but wont go on to create a second one afterwards.

Share this post


Link to post
Share on other sites

edit - my bad, I thought emptydetector was the name of the trigger - its the type

Edited by [EVO] Dan

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
Sign in to follow this  

×