Jump to content
kOepi

switch / do script not working - noob help please

Recommended Posts

Hey guys,

 

I got several switch dos running until day and now I am trying to make another one to supervise my gearscript.

 

fnc_Gear =
{
switch (_this) do
{
case "PL" : {call fnc_removeall;};
case "PL2" :{ execVM "scripts\loadouts\PL2.sqf";};
case "PS" : {execVM "scripts\loadouts\PS.sqf";};
case "PS2" :{ execVM "scripts\loadouts\PS2.sqf";};
case "FRO" :{ execVM "scripts\loadouts\P22.sqf";};
};
};

fnc_Gear3 =
{
_this execVM "scripts\loadouts\PL.sqf";
};

fnc_Gear4 = {
private ["_unit"];
_unit = switch (_this select 1) do {
case 1:{"scripts\loadouts\PL.sqf"};
case 2:{"scripts\loadouts\PS.sqf"};
case 3:{"rhsusf_ach_bare_des"};
case 4:{"rhsusf_ach_bare_des_headset"};
case 5:{"rhsusf_ach_bare_semi_headset"};
case 6:{"tin_helmet_fra_ce"};
case 7:{"ACC_H_MICH_D"};
default {""};
};
if (_unit == "") exitWith {false};
(_this select 0) execVM _unit;
true;
};

 

fnc_gear3 is working, fnc_gear is not, neither is fnc_gear4 is.

seems to me like a simple structure/syntax problem, hopefully someone can tell me what it is.

 

I call the scripts through the init field in the unit respectively for testing purposes:

 

[this, 1] call fnc_Gear4

 

[this, PL] call fnc_Gear

[this, PS] call fnc_Gear

[this] call fnc_gear3

 

 

please help me !

Share this post


Link to post
Share on other sites

You're passing an array to fnc_Gear. When you're switching _this inside that function, you're switching that very array, but your cases all expect strings, so that won't work. So what you wanna do instead is switch (_this select 1) do ...

 

And secondly, if you want to pass "PL" and "PS" to your fnc_Gear, you should put them in "quotes", because the way you posted it, you are passing some global variables PL and PS which with high probability don't exist. So, assuming you're putting the two call lines into some unit's init lines, they should look like this:

[this, "PL"] call fnc_Gear
[this, "PS"] call fnc_Gear

Share this post


Link to post
Share on other sites

mhm. doesnt work:

fnc_Gear2 =
{
	switch (_this select 1) do 
	{
		case "PL":{call fnc_removeall;};
		case "PL2":{execVM "scripts\loadouts\PL2.sqf";};
		case "PS":{execVM "scripts\loadouts\PS.sqf";};
		case "PS2":{execVM "scripts\loadouts\PS2.sqf";};
		case "FRO":{execVM "scripts\loadouts\P22.sqf";};
	};
};

[this, "PL"] call fnc_gear2

[this, "PL2"] call fnc_gear2

 

even get an error message:

 

PL2.sqf

private ["_GMC"];
_GMC = |#|_this select 0;
IF(!local _GMC) exitwith {};

 

Error undefined variable in expression

 

This is what my PL2.sqf looks like:

//	Guerilla Marines Platoon leader
private ["_GMC"];
_GMC = _this select 0;
IF(!local _GMC) exitwith {};
waitUntil { !isNull player };

_GMC call fnc_removeall;

//	clothing
//[_GMC,1] call fnc_giveHeadGear;
//[_GMC,3] call fnc_giveFaceW;

[_GMC,8] call fnc_giveUniform;
[_GMC,1] call fnc_giveVest;
//[_GMC,1] call fnc_giveBackPack;

// items - Radio
_GMC call fnc_giveCmps;
_GMC call fnc_giveMS;
_GMC call fnc_giveitems;
_GMC call fnc_givecableties;

//	weapons
_GMC call fnc_giveWAK74_1;
_GMC call fnc_giveWMakS;
_GMC call fnc_givegrensVA;

// backpack content

// 18.65 kg

Share this post


Link to post
Share on other sites

Your script is requiring an argument to be passed when executed (which would be _this select 0):

fnc_Gear2 =
{
	switch (_this select 1) do 
	{
		case "PL":{[(_this select 0)] call fnc_removeall;};
		case "PL2":{[(_this select 0)] execVM "scripts\loadouts\PL2.sqf";};
		case "PS":{[(_this select 0)] execVM "scripts\loadouts\PS.sqf";};
		case "PS2":{[(_this select 0)] execVM "scripts\loadouts\PS2.sqf";};
		case "FRO":{[(_this select 0)] execVM "scripts\loadouts\P22.sqf";};
	};
};
  • Like 1

Share this post


Link to post
Share on other sites

AWESOME, thank you very much, finally I got it working !

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

×