Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Sign in to follow this  
R4IDER

Undefined Variable Solution

Recommended Posts

Hi,

I have ran into an undefined variable error which usually is pretty easy to fix but in this case I am not sure how to go about removing the error. What I am doing is giving players their gear when they spawn. To do this I have given each unit a unique name of p1,p2,p3 for example and then using the code below to check if that unique name is in an array, if it is I then call my function which gives the player their gear. The problem is that I get an undefined variable error for all of the unique names and I am not to sure how I would go about fixing this. I have tried adding quotes around my array items but this breaks the script, can anyone recommend a solution? thanks.

_inplatoon = player in [p1];
_infac = player in [p2];
_insquadleaders = player in [p3,p8,p13,p18,p23,p28];
_inriflemen = player in [p4,p9,p14,p19,p24,p29];
_ingrenadiers = player in [p5,p10,p15,p20,p25,p30];
_inasstgunners = player in [p6,p11,p16,p21,p26,p31];
_inautomatics = player in [p7,p12,p17,p22,p27,p32];
_inpilots = player in [p33,p34,p35,p37,p38];
if(_inplatoon) then {
[player] call GOL_PL;
};
if(_infac) then {
[player] call GOL_FAC;
};
if(_insquadleaders) then {
[player] call GOL_SQ_TL;
};
if(_inriflemen) then {
[player] call GOL_RIFLEMAN;
};
if(_ingrenadiers) then {
[player] call GOL_GRENADIER;
};
if(_inasstgunners) then {
[player] call GOL_ASSISTANT_GUNNER;
};
if(_inautomatics) then {
[player] call GOL_AUTOMATIC_RIFLEMAN;
};
if(_inpilots) then {
[player] call GOL_PILOT;
};

Share this post


Link to post
Share on other sites

When you added quotes, did you also make the player variable a string?

_insquadleaders = (str player) in ["p3","p8","p13"]; 

Share this post


Link to post
Share on other sites

I didn't cuel, thank you that solved the issue.

Share this post


Link to post
Share on other sites

I think I might have a similar problem right now:

{
switch (true) do {
	case (_x == p1): { 
		[_x] execVM "loadouts\standard\leader.sqf";
	};
	case (_x == p2): { 
		[_x] execVM "loadouts\standard\medic.sqf";
	};
	case (_x == p3): { 
		[_x] execVM "loadouts\standard\marksman.sqf";
	};
};
}forEach allUnits;

is what I use to give my units their loadouts right now. It works perfectly fine, except that I get the undefined variable-popup for every unit that is not in the game (without any consequences though). I'm really not too keen on using an if (!isNull XYZ) {}; for every unit, so I wonder if there's another way (and don't see a way to apply the script above to my case. :()

Edited by Pergor

Share this post


Link to post
Share on other sites
Sign in to follow this  

×