Jump to content
hobbesy

_this returning as an undefined variable in a script

Recommended Posts

Edit: I forgot to use nul = [this] execVM in my script instead of just nul = execVM. How embarrassing. Mods can lock/delete this if you need to.



I'm having a very odd problem today, and it's one I haven't encountered before using other people's scripts. I'm messing around with a snippet samatra wrote here for adding a random weapon to a unit's inventory, and while it worked fairly well with the way I had it set up for adding to a player's inventory I've run into a snag in trying to set it up to work with the inventory of a unit who's init it's run in.

 

This is a screenshot of the undefined variable message I get on mission load, and below is the code I'm using.

 

waitUntil {!isNull player};

//Define a weapon, then its magazine.
weaponList = [
	["arifle_Katiba_F", "30Rnd_65x39_caseless_green"],
	["arifle_Katiba_C_F", "30Rnd_65x39_caseless_green"]
];

//Choose a random weapon.
_weapon = weaponList select floor(random(count weaponList));

//Select _guy
_guy = _this select 0;

//Give _guy a random weapon.
_guy addWeapon (_weapon select 0);

//Give _guy six magazines.
for "_i" from 0 to 6 do {
_guy addMagazine (_weapon select 1);
};

if(true) exitWith{};

For the life of me I can't figure out why _this would return as undefined aside from it needing to be defined, but I've never seen that done in other people's scripting. It's really done me up.

Share this post


Link to post
Share on other sites

Your entire script could be simplified a lot using recently added commands.

Also the last line makes no sense.

 

waitUntil {!isNull player};
//Select _guy
params ["_guy"];

//Choose a random weapon.
_rndWeap = selectRandom ["arifle_Katiba_F", "arifle_Katiba_C_F"];

//Give _guy a random weapon.
_addWeap = [_guy,_rndWeap,6] call BIS_fnc_addWeapon;

 

Cheers

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

×