Jump to content
red62dota

Local variables not defined inside control structures in script?

Recommended Posts

Hello, I have been working on this code for a mission for the past couple hours. I need to call it with four different units, like this: 

 

[bLUF_LEAD, "blufor_asset_1", "blufor_asset_2", "blufor_asset_3", "blufor_asset_4"] execVM "assets_core.sqf";

 

Before I attempted to call it with two units, every part of the script worked fine, but when I attempted to call it with the second team lead I realized that all the variables were global and it screwed up everything. In an attempt to fix this, I made all the unit and asset1-4 variables local - but now they do not get passed to the rest of the script for some reason. I get an undefined variable error around line 54 when I try to use _asset1. Can someone please help me figure out why my local variables (which should have a scope of the entire script) are not usable throughout the entire script? Many thanks.

/*
DONE: define spawn locations for assets, boxes etc - primary spawn, secondary spawn
blufor_asset_1-4
civ_asset_1-4
indfor_asset_1-4
redfor_asset_1-4
*/

sleep 2;

_unit = _this select 0;
_asset1 = _this select 1;
_asset2 = _this select 2;
_asset3 = _this select 3;
_asset4 = _this select 4;



//DIFFERENTIATE BETWEEN RIFLES
if (side _unit == west) then 
{
    dmrScope = "rhs_acc_1p78";
    redDot = "CUP_optic_Kobra";
    silencer = "rhs_acc_tgpa";
};
if (side _unit == east) then
{
    dmrScope = "RH_ta31rco";
    redDot = "FHQ_optic_AC11704";
    silencer = "CUP_muzzle_snds_G36_black";
    
};
if (side _unit == resistance) then
{
    dmrScope = "RH_ta31rco";
    redDot = "optic_Aco";
    silencer = "muzzle_snds_M";
    
};
if (side _unit == civilian) then
{
    dmrScope = "RH_ta31rco";
    redDot = "optic_Aco";
    silencer = "muzzle_snds_B";
    
};

//PICK PRIMARY ASSET
a = 0;
while {a != 1} do
{
    if (a == 0) then
    {
        _unit addAction ["1x HMMWV (M2)", {a = 1; _veh = "rhsusf_m1025_d_m2" createVehicle(getMarkerPos _asset1); clearWeaponCargo _veh; clearMagazineCargo _veh; clearBackpackCargo _veh; removeAllActions _unit;}];
        _unit addAction ["2x HMMWV (UNARMED)", {a = 1; _veh = "rhsusf_m1025_d" createVehicle(getMarkerPos _asset1); clearWeaponCargo _veh; clearMagazineCargo _veh; clearBackpackCargo _veh; _veh = "rhsusf_m1025_d" createVehicle(getMarkerPos _asset4); clearWeaponCargo _veh; clearMagazineCargo _veh; clearBackpackCargo _veh; removeAllActions _unit;}];
        _unit addAction ["1x Littlebird (UNARMED)", {a = 1;_veh = "CUP_B_MH6J_USA" createVehicle(getMarkerPos _asset1); clearWeaponCargo _veh; clearMagazineCargo _veh; clearBackpackCargo _veh; removeAllActions _unit;}];
        _unit addAction ["1x HMMWV (GPMG)", {a = 1;_veh = "CUP_B_HMMWV_MK19_USA" createVehicle(getMarkerPos _asset1); clearWeaponCargo _veh; clearMagazineCargo _veh; clearBackpackCargo _veh; _veh setVehicleAmmo .18; removeAllActions _unit;}];
        _unit addAction ["4x Quadbike", {a = 1; _veh = "C_Quadbike_01_F" createVehicle(getMarkerPos _asset1); _veh = "C_Quadbike_01_F" createVehicle(getMarkerPos _asset1);_veh = "C_Quadbike_01_F" createVehicle(getMarkerPos _asset1);_veh = "C_Quadbike_01_F" createVehicle(getMarkerPos _asset1); removeAllActions _unit;}];
        _unit addAction ["1x HMMWV (TOW)", {a = 1; _veh = "CUP_B_HMMWV_TOW_USMC" createVehicle(getMarkerPos _asset1); clearWeaponCargo _veh; clearMagazineCargo _veh; clearBackpackCargo _veh; _veh setVehicleAmmo .40; removeAllActions _unit;}];
                
        a = 2
    };
    sleep 1;
    
};

sleep 2;
//PICK SECONDARY ASSET
box = "Box_East_Ammo_F" createVehicle(getMarkerPos _asset2);
clearMagazineCargo box;

b = 0;
while {b != 1} do
{
    if (b == 0) then
    {
        _unit addAction ["1x L115A1 Sniper w/ optics", {b = 1; box addWeaponCargo ["CUP_srifle_AWM_des",1]; box addMagazineCargo ["CUP_5Rnd_86x70_L115A1",10]; box addItemCargo ["CUP_optic_LeupoldMk4_10x40_LRT_Desert",1]; removeAllActions _unit;}];
        _unit addAction ["2x AA12", {b = 1; box addWeaponCargo ["CUP_sgun_AA12",2]; box addMagazineCargo ["CUP_20Rnd_B_AA12_Pellets",16]; box addMagazineCargo ["CUP_20Rnd_B_AA12_74Slug",16]; removeAllActions _unit;}];
        _unit addAction ["2x M249", {b = 1; box addWeaponCargo ["rhs_weap_m249_pip_L",2]; box addMagazineCargo ["rhs_200rnd_556x45_M_SAW",16]; removeAllActions _unit;}];
        _unit addAction ["2x M136 HEDP", {b = 1; box addWeaponCargo ["rhs_weap_M136_hedp",2]; removeAllActions _unit;}];
        _unit addAction ["2x M16 (M203)", {b = 1; box addWeaponCargo ["rhs_weap_m16a4_carryhandle_M203",2]; box addMagazineCargo ["rhs_mag_30Rnd_556x45_Mk318_Stanag",16]; box addItemCargo ["1Rnd_HE_Grenade_shell",60]; removeAllActions _unit;}];
        _unit addAction ["4x Mini Uzi w/ Suppressor", {b = 1; box addWeaponCargo ["CUP_hgun_MicroUzi",4]; box addMagazineCargo ["CUP_30Rnd_9x19_UZI",50]; box addItemCargo ["CUP_muzzle_snds_MicroUzi",4]; removeAllActions _unit;}];
        b = 2;
    };
    sleep 1;
};

//PICK TERTIARY ASSET
sleep 2;

a = 0;
while {a != 1} do
{
    if (a == 0) then
    {
        _unit addAction ["2x IED", {a = 1; box addItemCargo ["CUP_IED_V1_M",2]; removeAllActions _unit;}];
        _unit addAction ["6x M15 AT Mine", {a = 1; box addItemCargo ["ATMine_Range_Mag",6]; removeAllActions _unit;}];
        _unit addAction ["12x L109 Frag", {a = 1; box addItemCargo ["CUP_HandGrenade_L109A1_HE",12]; removeAllActions _unit;}];
        _unit addAction ["10x M84 Stun", {a = 1; box addItemCargo ["rhs_mag_mk84",10]; removeAllActions _unit;}];
        _unit addAction ["15x M18 Smoke", {a = 1; box addItemCargo ["SmokeShellBlue",15]; removeAllActions _unit;}];
        _unit addAction ["2x Steerable Parachute", {a = 1; box addBackpackCargo ["B_Parachute",2]; removeAllActions _unit;}];
        _unit addAction ["4x Red dot", {a = 1; box addItemCargo [redDot,4]; removeAllActions _unit;}];
        _unit addAction ["4x Suppressor", {a = 1; box addItemCargo [silencer,4]; removeAllActions _unit;}];
        _unit addAction ["2x DMR optics", {a = 1; box addItemCargo [dmrScope,2]; removeAllActions _unit;}];
        _unit addAction ["Extra medical supplies", {a = 1; box addItemCargo ["ACE_elasticBandage",30]; box addItemCargo ["ACE_packingBandage",30]; box addItemCargo ["ACE_morphine",15]; box addItemCargo ["ACE_epinephrine",15]; box addItemCargo ["ACE_personalAidKit",10]; box addItemCargo ["ACE_salineIV_250",10]; removeAllActions _unit;}];
        
        a = 2;
    };
    sleep 1;
};


//TODO: delete border fences around units after 2 minutes or so

Share this post


Link to post
Share on other sites

I've got no clue what you are doing there. Why are you using while loops for those actions? Additionally, if you want to use global variables, don't name them a or b or assets. Always add a unique tag infront of them. Revo_asset_1

Share this post


Link to post
Share on other sites

I've got no clue what you are doing there. Why are you using while loops for those actions? Additionally, if you want to use global variables, don't name them a or b or assets. Always add a unique tag infront of them. Revo_asset_1

 

The while loop checks if the addactions have been given to the unit, and if so it sleeps 1 then repeats until one of the addactions has been selected by the unit, in which case the script can proceed to the next block - it happens sequentially. I know I should name my variables better, sorry about that

Share this post


Link to post
Share on other sites

Everything works fine when the vars are all global, but when I switch them to local they do not get propagated down from the main body of the script into ANY control structures or anything with brackets in it whatsoever

Share this post


Link to post
Share on other sites

When your variables are local they need to be passed into the actions code.

An actions code is deferred to run when the action is used and so the variables are undefined as the actions code knows nothing about the scope the actions where defined in.

_unit addAction [ "1x HMMWV (M2)", {
	params[ "_target", "_caller", "_ID", "_mrk" ]; //retrieve the passed variable _mrk
	
	_veh = "rhsusf_m1025_d_m2" createVehicle(getMarkerPos _mrk);
	clearWeaponCargo _veh;
	clearMagazineCargo _veh;
	clearBackpackCargo _veh;
	
	removeAllActions _caller;
	
}, _asset1 ]; //pass the variable into the actions code


_unit addAction [ "2x HMMWV (UNARMED)", {
	params[ "_target", "_caller", "_ID", "_args" ];
	_args params[ "_mrk1", "_mrk2" ];
	
	_veh = "rhsusf_m1025_d" createVehicle(getMarkerPos _mrk1);
	clearWeaponCargo _veh;
	clearMagazineCargo _veh;
	clearBackpackCargo _veh;
	_veh = "rhsusf_m1025_d" createVehicle(getMarkerPos _mrk2);
	clearWeaponCargo _veh;
	clearMagazineCargo _veh;
	clearBackpackCargo _veh;
	
	removeAllActions _caller;
	
}, [ _asset1, _asset4 ] ];
I have to agree with R3vo though that your logic for waiting for action use could be done better.

params[ "_unit", "_asset1", "_asset2", "_asset3", "_asset4" ];

//Choose weapon items via units side
[
	[ "RH_ta31rco", "FHQ_optic_AC11704", "CUP_muzzle_snds_G36_black" ], //EAST
	[ "rhs_acc_1p78", "CUP_optic_Kobra", "rhs_acc_tgpa" ],				//WEST
	[ "RH_ta31rco", "optic_Aco", "muzzle_snds_M" ],						//RESISTANCE
	[ "RH_ta31rco", "optic_Aco", "muzzle_snds_B" ]						//CIVILIAN
] select ( side _unit call BIS_fnc_sideID ) params [ "_dmr", "_dot", "_silencer" ];

//Spawn box for items
_box = "Box_East_Ammo_F" createVehicle(getMarkerPos _asset2);
clearWeaponCargoGlobal _box;
clearMagazineCargoGlobal _box;
clearBackpackCargoGlobal _box;
clearItemCargoGlobal _box;

//function to create vehicle, clear cargo and change ammo if required
fnc_createVehicleAssets = {
	params[ "_info", "_unit" ];
	
	{
		_x params [ "_vehType", "_mrk", [ "_vehAmmo", 1 ] ];
		_veh = createVehicle [ _vehType, getMarkerPos _mrk, [], 0, "NONE" ];
		clearWeaponCargoGlobal _veh;
		clearMagazineCargoGlobal _veh;
		clearBackpackCargoGlobal _veh;
		clearItemCargoGlobal _veh;
		_veh setVehicleAmmo _vehAmmo;
	}forEach _info;
	
	//trigger action change
	_unit setVariable[ "assetChoosen", true ];

};

//function to fill box with items
fnc_createBoxAssets = {
	params[ "_info", "_unit" ];
	_info params[ "_box", "_items" ];
	
	{
		_x params[ "_className" ];
		_itemInfo = _className call BIS_fnc_itemType;
		switch ( toLower ( _itemInfo select 0 ) ) do {
			case "mine";
			case "magazine" : {
				_box addMagazineCargoGlobal _x;
			};
			case "weapon" : {
				_box addWeaponCargoGlobal _x;
			};
			case "item" : {
				_box addItemCargoGlobal _x;
			};
			case "equipment" : {
				if ( _itemInfo select 1 == "backpack" ) then {
					_box addBackpackCargo _x;
				}else{
					_box addItemCargoGlobal _x;
				};
			};
		};
	}forEach _items;
	
	//trigger action change
	_unit setVariable[ "assetChoosen", true ];
};

//Action sets
//[
//	function to call,
//	[
//		[ action title, info to pass to function ]
//	]
//]

_primaryAssets = [
	"fnc_createVehicleAssets",
	[
		["1x HMMWV (M2)", [ [ "rhsusf_m1025_d_m2", _asset1 ] ] ],
		["2x HMMWV (UNARMED)", [ [ "rhsusf_m1025_d", _asset1 ], [ "rhsusf_m1025_d", _asset4 ] ] ], 
		["1x Littlebird (UNARMED)", [ [ "CUP_B_MH6J_USA", _asset1 ] ] ],
		["1x HMMWV (GPMG)", [ [ "CUP_B_HMMWV_MK19_USA", _asset1, 0.18 ] ] ],
		["4x Quadbike",	[ [ "C_Quadbike_01_F", _asset1 ], [ "C_Quadbike_01_F", _asset1 ], [ "C_Quadbike_01_F", _asset1 ], [ "C_Quadbike_01_F", _asset1 ] ] ],
		["1x HMMWV (TOW)", [ [ "CUP_B_HMMWV_TOW_USMC", _asset1, 0.40 ] ] ]
	]
];

_secondaryAssets = [
	"fnc_createBoxAssets",
	[
		["1x L115A1 Sniper w/ optics", [ _box, [ ["CUP_srifle_AWM_des",1], ["CUP_5Rnd_86x70_L115A1",10], ["CUP_optic_LeupoldMk4_10x40_LRT_Desert",1] ] ] ],
		["2x AA12", [ _box,[ ["CUP_sgun_AA12",2], ["CUP_20Rnd_B_AA12_Pellets",16], ["CUP_20Rnd_B_AA12_74Slug",16] ] ] ],
		["2x M249", [ _box, [ ["rhs_weap_m249_pip_L",2], ["rhs_200rnd_556x45_M_SAW",16] ] ] ],
		["2x M136 HEDP", [ _box, [ ["rhs_weap_M136_hedp",2] ] ] ],
		["2x M16 (M203)", [ _box, [ ["rhs_weap_m16a4_carryhandle_M203",2], ["rhs_mag_30Rnd_556x45_Mk318_Stanag",16], ["1Rnd_HE_Grenade_shell",60] ] ] ],
		["4x Mini Uzi w/ Suppressor", [ _box, [ ["CUP_hgun_MicroUzi",4], ["CUP_30Rnd_9x19_UZI",50], ["CUP_muzzle_snds_MicroUzi",4] ] ] ]
	]
];

_tertiaryAssets = [
	"fnc_createBoxAssets",
	[
		["2x IED", [ _box, [ ["CUP_IED_V1_M",2] ] ] ],
		["6x M15 AT Mine", [ _box, [ ["ATMine_Range_Mag",6] ] ] ],
		["12x L109 Frag", [ _box, [ ["CUP_HandGrenade_L109A1_HE",12] ] ] ],
		["10x M84 Stun", [ _box, [ ["rhs_mag_mk84",10] ] ] ],
		["15x M18 Smoke", [ _box, [ ["SmokeShellBlue",15] ] ] ],
		["2x Steerable Parachute", [ _box, [ ["B_Parachute",2] ] ] ],
		["4x Red dot", [ _box, [ [_dot,4] ] ] ],
		["4x Suppressor", [ _box, [ [_silencer,4] ] ] ],
		["2x DMR optics", [ _box, [ [_dmr,2] ] ] ],
		["Extra medical supplies", [ _box, [ ["ACE_elasticBandage",30], ["ACE_packingBandage",30], ["ACE_morphine",15], ["ACE_epinephrine",15], ["ACE_personalAidKit",10], ["ACE_salineIV_250",10] ] ] ]
	]
];

private _fnc_createAssetActions = {
	params[ "_unit", "_actionInfo" ];
	_actionInfo params[ "_func", "_actions" ];
	
	_ids = [];
	{
		_x params [ "_title", "_Info" ];
		
		_nul = _ids pushBack ( _unit addAction [ _title, {
				param[ 3 ] params[ "_func", "_Info", "_unit" ]; //retrieve action arguments
				
				[ _info, _unit ] call ( missionNamespace getVariable _func ); //call function passing info
			},
			[ _func, _Info, _unit ] //pass function and info from action set into the actions arguments
		] );

	}forEach _actions;
	
	//store added action ids on unit
	_unit setVariable [ "assetActionIDs", _ids ];
};

{
	//create the actions
	[ _unit, _x ] call _fnc_createAssetActions;
	
	//wait for a action to be used
	waitUntil { !isNil { _unit getVariable [ "assetChoosen", nil ] } };
	
	//reset use flag
	_unit setVariable[ "assetChoosen", nil ];
	
	//remove all action set actions
	{
		_unit removeAction _x;
	}forEach ( _unit getVariable [ "assetActionIDs", [] ] ) ;
		
}forEach [ _primaryAssets, _secondaryAssets, _tertiaryAssets ]; //each asset set
  • Like 2

Share this post


Link to post
Share on other sites

When your variables are local they need to be passed into the actions code.

An actions code is deferred to run when the action is used and so the variables are undefined as the actions code knows nothing about the scope the actions where defined in.

_unit addAction [ "1x HMMWV (M2)", {
	params[ "_target", "_caller", "_ID", "_mrk" ]; //retrieve the passed variable _mrk
	
	_veh = "rhsusf_m1025_d_m2" createVehicle(getMarkerPos _mrk);
	clearWeaponCargo _veh;
	clearMagazineCargo _veh;
	clearBackpackCargo _veh;
	
	removeAllActions _caller;
	
}, _asset1 ]; //pass the variable into the actions code


_unit addAction [ "2x HMMWV (UNARMED)", {
	params[ "_target", "_caller", "_ID", "_args" ];
	_args params[ "_mrk1", "_mrk2" ];
	
	_veh = "rhsusf_m1025_d" createVehicle(getMarkerPos _mrk1);
	clearWeaponCargo _veh;
	clearMagazineCargo _veh;
	clearBackpackCargo _veh;
	_veh = "rhsusf_m1025_d" createVehicle(getMarkerPos _mrk2);
	clearWeaponCargo _veh;
	clearMagazineCargo _veh;
	clearBackpackCargo _veh;
	
	removeAllActions _caller;
	
}, [ _asset1, _asset4 ] ];
I have to agree with R3vo though that your logic for waiting for action use could be done better.

params[ "_unit", "_asset1", "_asset2", "_asset3", "_asset4" ];

//Choose weapon items via units side
[
	[ "RH_ta31rco", "FHQ_optic_AC11704", "CUP_muzzle_snds_G36_black" ], //EAST
	[ "rhs_acc_1p78", "CUP_optic_Kobra", "rhs_acc_tgpa" ],				//WEST
	[ "RH_ta31rco", "optic_Aco", "muzzle_snds_M" ],						//RESISTANCE
	[ "RH_ta31rco", "optic_Aco", "muzzle_snds_B" ]						//CIVILIAN
] select ( side _unit call BIS_fnc_sideID ) params [ "_dmr", "_dot", "_silencer" ];

//Spawn box for items
_box = "Box_East_Ammo_F" createVehicle(getMarkerPos _asset2);
clearWeaponCargoGlobal _box;
clearMagazineCargoGlobal _box;
clearBackpackCargoGlobal _box;
clearItemCargoGlobal _box;

//function to create vehicle, clear cargo and change ammo if required
fnc_createVehicleAssets = {
	params[ "_info", "_unit" ];
	
	{
		_x params [ "_vehType", "_mrk", [ "_vehAmmo", 1 ] ];
		_veh = createVehicle [ _vehType, getMarkerPos _mrk, [], 0, "NONE" ];
		clearWeaponCargoGlobal _veh;
		clearMagazineCargoGlobal _veh;
		clearBackpackCargoGlobal _veh;
		clearItemCargoGlobal _veh;
		_veh setVehicleAmmo _vehAmmo;
	}forEach _info;
	
	//trigger action change
	_unit setVariable[ "assetChoosen", true ];

};

//function to fill box with items
fnc_createBoxAssets = {
	params[ "_info", "_unit" ];
	_info params[ "_box", "_items" ];
	
	{
		_x params[ "_className" ];
		_itemInfo = _className call BIS_fnc_itemType;
		switch ( toLower ( _itemInfo select 0 ) ) do {
			case "mine";
			case "magazine" : {
				_box addMagazineCargoGlobal _x;
			};
			case "weapon" : {
				_box addWeaponCargoGlobal _x;
			};
			case "item" : {
				_box addItemCargoGlobal _x;
			};
			case "equipment" : {
				if ( _itemInfo select 1 == "backpack" ) then {
					_box addBackpackCargo _x;
				}else{
					_box addItemCargoGlobal _x;
				};
			};
		};
	}forEach _items;
	
	//trigger action change
	_unit setVariable[ "assetChoosen", true ];
};

//Action sets
//[
//	function to call,
//	[
//		[ action title, info to pass to function ]
//	]
//]

_primaryAssets = [
	"fnc_createVehicleAssets",
	[
		["1x HMMWV (M2)", [ [ "rhsusf_m1025_d_m2", _asset1 ] ] ],
		["2x HMMWV (UNARMED)", [ [ "rhsusf_m1025_d", _asset1 ], [ "rhsusf_m1025_d", _asset4 ] ] ], 
		["1x Littlebird (UNARMED)", [ [ "CUP_B_MH6J_USA", _asset1 ] ] ],
		["1x HMMWV (GPMG)", [ [ "CUP_B_HMMWV_MK19_USA", _asset1, 0.18 ] ] ],
		["4x Quadbike",	[ [ "C_Quadbike_01_F", _asset1 ], [ "C_Quadbike_01_F", _asset1 ], [ "C_Quadbike_01_F", _asset1 ], [ "C_Quadbike_01_F", _asset1 ] ] ],
		["1x HMMWV (TOW)", [ [ "CUP_B_HMMWV_TOW_USMC", _asset1, 0.40 ] ] ]
	]
];

_secondaryAssets = [
	"fnc_createBoxAssets",
	[
		["1x L115A1 Sniper w/ optics", [ _box, [ ["CUP_srifle_AWM_des",1], ["CUP_5Rnd_86x70_L115A1",10], ["CUP_optic_LeupoldMk4_10x40_LRT_Desert",1] ] ] ],
		["2x AA12", [ _box,[ ["CUP_sgun_AA12",2], ["CUP_20Rnd_B_AA12_Pellets",16], ["CUP_20Rnd_B_AA12_74Slug",16] ] ] ],
		["2x M249", [ _box, [ ["rhs_weap_m249_pip_L",2], ["rhs_200rnd_556x45_M_SAW",16] ] ] ],
		["2x M136 HEDP", [ _box, [ ["rhs_weap_M136_hedp",2] ] ] ],
		["2x M16 (M203)", [ _box, [ ["rhs_weap_m16a4_carryhandle_M203",2], ["rhs_mag_30Rnd_556x45_Mk318_Stanag",16], ["1Rnd_HE_Grenade_shell",60] ] ] ],
		["4x Mini Uzi w/ Suppressor", [ _box, [ ["CUP_hgun_MicroUzi",4], ["CUP_30Rnd_9x19_UZI",50], ["CUP_muzzle_snds_MicroUzi",4] ] ] ]
	]
];

_tertiaryAssets = [
	"fnc_createBoxAssets",
	[
		["2x IED", [ _box, [ ["CUP_IED_V1_M",2] ] ] ],
		["6x M15 AT Mine", [ _box, [ ["ATMine_Range_Mag",6] ] ] ],
		["12x L109 Frag", [ _box, [ ["CUP_HandGrenade_L109A1_HE",12] ] ] ],
		["10x M84 Stun", [ _box, [ ["rhs_mag_mk84",10] ] ] ],
		["15x M18 Smoke", [ _box, [ ["SmokeShellBlue",15] ] ] ],
		["2x Steerable Parachute", [ _box, [ ["B_Parachute",2] ] ] ],
		["4x Red dot", [ _box, [ [_dot,4] ] ] ],
		["4x Suppressor", [ _box, [ [_silencer,4] ] ] ],
		["2x DMR optics", [ _box, [ [_dmr,2] ] ] ],
		["Extra medical supplies", [ _box, [ ["ACE_elasticBandage",30], ["ACE_packingBandage",30], ["ACE_morphine",15], ["ACE_epinephrine",15], ["ACE_personalAidKit",10], ["ACE_salineIV_250",10] ] ] ]
	]
];

private _fnc_createAssetActions = {
	params[ "_unit", "_actionInfo" ];
	_actionInfo params[ "_func", "_actions" ];
	
	_ids = [];
	{
		_x params [ "_title", "_Info" ];
		
		_nul = _ids pushBack ( _unit addAction [ _title, {
				param[ 3 ] params[ "_func", "_Info", "_unit" ]; //retrieve action arguments
				
				[ _info, _unit ] call ( missionNamespace getVariable _func ); //call function passing info
			},
			[ _func, _Info, _unit ] //pass function and info from action set into the actions arguments
		] );

	}forEach _actions;
	
	//store added action ids on unit
	_unit setVariable [ "assetActionIDs", _ids ];
};

{
	//create the actions
	[ _unit, _x ] call _fnc_createAssetActions;
	
	//wait for a action to be used
	waitUntil { !isNil { _unit getVariable [ "assetChoosen", nil ] } };
	
	//reset use flag
	_unit setVariable[ "assetChoosen", nil ];
	
	//remove all action set actions
	{
		_unit removeAction _x;
	}forEach ( _unit getVariable [ "assetActionIDs", [] ] ) ;
		
}forEach [ _primaryAssets, _secondaryAssets, _tertiaryAssets ]; //each asset set

 

 

 

Thanks. I only have a couple years of Java and Python experience, and I have been trying to work through a couple scripts in my unit's modpack to try to understand them, but I find this language incredibly hard to read in general. Your code looks beautiful, but I am definitely going to have to read up on some Arma 3 specific control structures, reserved commands and variable interaction before I am able to trace it and fully understand it. Thanks again for your assistance.

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

×