Jump to content
revv

[SOLVED] Trouble selecting element in array

Recommended Posts

Hello I am having trouble with part of my script, I am using a random roadside IED script found here: https://forums.bistudio.com/topic/161027-randomly-generated-roadside-ieds/
That is just for reference. here is the whole of my mission script I am having an issue with:
mission_3.sqf
 

//  Set mission status for JIP
missionStatus = 13;
//  Code that actually sends this out to other players.
publicVariable "missionStatus";
publicVariable "iedX";

[WEST, 	["tsk1"], 
		["Find & disarm the 3 IED's", 
		"Find & Disarm", 
		"Disarm"], 
		[objNull], 1, 2, true] call BIS_fnc_taskCreate;
sleep 1;

if(!isServer) exitWith{};

//////Thanks Will for help on this one\\\\\\
_iedX = [["iedMkr_1", 3, 20, "West"]] call CREATE_IED_SECTION;
_iedArray = _iedX select 0;
_iedSelect = _iedArray select 1;
sleep 1;

//  Create marker at the location
	_marker = createMarker ["iedTargetMkr", getmarkerpos "iedMkr_1"];
	_marker setMarkerType "hd_objective";
	_marker setMarkerColor "ColorYellow";
	_marker setMarkerText "Search";

waitUntil {sleep 0.5; _iedSelect == 3;
hint "IED's Remaining: 3";
};
waitUntil {sleep 0.5; _iedSelect == 2;
hint "IED's Remaining: 2";
};
waitUntil {sleep 0.5; _iedSelect == 1;
hint "IED's Remaining: 1";
};
waitUntil {sleep 0.5; _iedSelect == 0;};

["tsk1", "SUCCEEDED",true] spawn BIS_fnc_taskSetState; 
_iedX call REMOVE_IED_SECTION;
deleteMarker "iedTargetMkr";
sleep 1;

["tsk1", WEST] spawn BIS_fnc_deleteTask; 
sleep 3;

"scripts\initMissions.sqf" remoteExec ["execVM",2];

From line 17 - 19 (the trouble part)
 

_iedX = [["iedMkr_1", 3, 20, "West"]] call CREATE_IED_SECTION;
_iedArray = _iedX select 0;
_iedSelect = _iedArray select 1;

I am trying to select the second element of the _iedX array (the number 3) so I can keep count how many IED's are left for the player but it keeps returning : generic error in expression at line 18 - "_iedX #select 0;"
Any hints or ideas on how to do this correctly?

Share this post


Link to post
Share on other sites

Oh and I know the public variable for iedX is not being used right now I forgot to remove it.

Share this post


Link to post
Share on other sites

maybe the problem is caused by CREATE_IED_SECTION. u should check if it returns ur desired array. u could count its elements first.

Share this post


Link to post
Share on other sites

maybe the problem is caused by CREATE_IED_SECTION. u should check if it returns ur desired array. u could count its elements first.

So after some more research I do think it's to do with the functions (still learning ;)) 

So here is a question and it doesn't just relate to the IED scripts but I will use it as a reference since Im trying to get it working.

If I use this:

 

_iedCount = "iedSection" call GET_IED_SECTION_INFORMATION;

it says on that particular script author's page that it's supposed to return [#IED'sExploded, #IED'sDisarmed]

How exactly would I detect if both of those values have reached "0" inside of a waitUntil?

Share this post


Link to post
Share on other sites


waitUntil

{

 sleep 1;      // or whatever u think is useful for a delay value but its essential to save fps

 _iedCount = "iedSection" call GET_IED_SECTION_INFORMATION;

(((_iedCount select 0) == 0) and ((_iedCount select 1) == 0))

};

Share this post


Link to post
Share on other sites
waitUntil
{
 sleep 1;      // or whatever u think is useful for a delay value but its essential to save fps
 _iedCount = "iedSection" call GET_IED_SECTION_INFORMATION;
(((_iedCount select 0) == 0) and ((_iedCount select 1) == 0))
};

It seems to be working now and you were on the right track there I used this in the end:

 

waitUntil {sleep 0.5; 
		("iedSection" call GET_REMAINING_IED_COUNT == 0)
		&& 
		{"iedSection" call GET_IED_SECTION_INFORMATION select 0 == 0}
		};

It's not giving any errors and I'm in testing phase now. Assume it works unless I report back otherwise. Thanks for your help!

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

×