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

Undefined variable....

Recommended Posts

My script:

if ((_type >= _lootChanceWeaponMin) && (_type <= _lootChanceWeaponMax)) 
	then {
		_weapon = _lootWeapon call bis_fnc_selectRandom; 

		_magazines = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines");
		_magazineClass = _magazines call bis_fnc_selectRandom; 

		_holder addWeaponCargoGlobal [_weapon, 1];
		_holder addMagazineCargoGlobal [_magazineClass, floor(random 3)];
	};

Error:

Error in expression <getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines");
_magazineClass >
 Error position: <_weapon >> "magazines");
_magazineClass >
 Error Undefined variable in expression: _weapon
File C:\Users\Yuval\Documents\Arma 3\missions\a3mission.Stratis\spawnloot.sqf, line 50

What's the problem?!

Share this post


Link to post
Share on other sites

Personally what I do in these cases is attempt to view the string of the variable in question. So, right after you attempt to define _weapon, put:

player sideChat str _weapon;

Or diag_log it, either works depending on the situation. This will tell you if the problem is the definition itself or not. In your case, my guess is that _lootWeapon is an empty array. So look back further.

Share this post


Link to post
Share on other sites
;2704332']Personally what I do in these cases is attempt to view the string of the variable in question. So' date=' right after you attempt to define _weapon, put:

player sideChat str _weapon;

Or diag_log it, either works depending on the situation. This will tell you if the problem is the definition itself or not. In your case, my guess is that _lootWeapon is an empty array. So look back further.[/quote']

When I did that (replaced player sideChat with hint so it will be easier for me to see), a lot of guns were rolled up as hints. What could do that then?

EDIT: Btw I thought it would be good if I'll point out what _lootWeapon is. _lootWeapon's origin is in a custom config file:

lootWeapon[] = 
	{
		"arifle_mas_akm",
		"arifle_mas_aks74u",
		"arifle_mas_ak_74m",
		"RH_ar10",
		"RH_m4",
		"RH_m16a4",
		"arifle_mas_hk416",
		"arifle_mas_bizon",
		"RH_mak",
		"RH_g17",
		"RH_usp"
	};

Also, when I load the mission - there's an error message at the bottom of the screen that is related to bis_fnc_selectrandom with a "fx" image in the bottom-right corner of the screen. This error also repeats itself in the .rpt several times.

Is it possible that the problem is in one of the weapons in the array? This is just a suggestion which I don't know the answer to. I am a scripting newbie

Edited by Yuval

Share this post


Link to post
Share on other sites

Well there you go. So your issue is in the definition of _weapon, and possibly further before. I believe you need to wrap the inside of that scope you just posted with brackets []. Were the weapons that came up in array format? Right now my guess is _lootWeapon is not an array, and thus you can't select anything, so its returning what you put in, which is _lootWeapon, which is not an array because you never defined it as one.

I'm not familiar with how you're defining the "custom config". As well, note you have lootWeapon and _lootWeapon. Those are not the same thing.

Share this post


Link to post
Share on other sites

Yet I still see weapons spawning (This is a loot system system). I found the following weapons already (while this error is popping up)

arifle_mas_aks74m

RH_m16a4

arifle_mas_bizon

EDIT: Solved it.

The problem was that I only set Military loot for some buildings and forgot to set Residental loot for the rest. I thought it wouldn't change if I'll just keep buildings with only loot positions stored but it seems like when the script pulled the data it didn't find any _lootWeapon (and other loot tables, such as backpacks, vests, attachments, items, cloth, etc...). Therefore the script returned an error since there was NO entry on _weapon when a residential building was proccessed in the script.

Thanks Grimes, you helped me alot (I didn't even think about _weapon being not defined).

Edited by Yuval

Share this post


Link to post
Share on other sites

Thanks Grimes, you helped me alot (I didn't even think about _weapon being not defined).

Happy to help. Just keep in mind that though sometimes the errors that come up seem ridiculous or useless, they always make sense in some way. Things don't break here, they just don't work in the first place. Process of elimination and using the concept of narrowing/isolating potential issues will get you a long way.

Share this post


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

×