Jump to content
Zeraw

Variable not defined error

Recommended Posts

Hey Guys!

I'm struggling with a "variable not define" error for the variable boatBase :
 

_BoatType = ["CUP_B_RHIB2Turret_USMC","B_G_Boat_Transport_01_F"] call BIS_fnc_selectRandom;
_chance1 = round (random 360);
_boatframe1 = [getMarkerPos "Boatstart_3", _chance1, _BoatType] call BIS_fnc_spawnVehicle;
boatBase = _boatframe1 select 0;
player moveInDriver boatBase;
{ _x assignAsCargo (boatBase); _x moveInAny (boatBase);} foreach units group player;

 wierd thing is that I just copy passed it from another script I wrote and this one is working fine:

 

_HstPos = getMarkerPos "HALOstart_2";
_planeType = ["B_T_VTOL_01_infantry_F","RHS_C130J"] call BIS_fnc_selectRandom;
_rndowiz = round (random 360);
planeTeam = creategroup WEST;
_planeprep = [getMarkerPos "HALOstart_2", _rndowiz, _planeType, planeTeam] call BIS_fnc_spawnVehicle;
planeBase = _planeprep select 0;
{if (!isNull (unitBackpack _x) && (backpack _x) != "b_parachute") then {
	private ["_pack","_class","_magazines","_weapons","_items","_helmet"];
	_pack	   = unitBackpack _x;
	_class	   = typeOf _pack;
	_magazines = getMagazineCargo _pack;
	_weapons   = getWeaponCargo _pack;
	_items	   = getItemCargo _pack;
	_helmet	   = headgear _x;
 
	removeBackpack _x; //remove the backpack
	_x addBackpack "b_parachute"; //add the parachute

	[_x,_class,_magazines,_weapons,_items,_helmet] spawn {
		private ["_x","_class","_magazines","_weapons","_items","_helmet"];
		_x		= _this select 0;
		_class		= _this select 1;
		_magazines	= _this select 2;
		_weapons 	= _this select 3;
		_items 		= _this select 4;
		_helmet		= _this select 5;
		
		
		private "_packHolder";
		_packHolder = createVehicle ["groundWeaponHolder", [0,0,0], [], 0, "can_collide"];
		_packHolder addBackpackCargoGlobal [_class, 1];
				
		waitUntil {animationState _x == "HaloFreeFall_non"};
		_packHolder attachTo [_x,[-0.12,-0.02,-.74],"pelvis"]; 
		_packHolder setVectorDirAndUp [[0,-1,-0.05],[0,0,-1]];
				
		waitUntil {animationState _x == "para_pilot"};
		_packHolder attachTo [vehicle _x,[-0.07,0.67,-0.13],"pelvis"]; 
		_packHolder setVectorDirAndUp [[0,-0.2,-1],[0,1,0]];
				
		waitUntil isTouchingGround _x;
		detach _packHolder;
		deleteVehicle _packHolder; 
			
		_x addBackpack _class; 
		clearAllItemsFromBackpack _x; 
		if (_helmet != "" && _helmet != "H_CrewHelmetplane_B") then {(unitBackpack _x) addItemCargoGlobal [_helmet, 1]}; //(not complete) do a check to see if there is available space

		for "_i" from 0 to (count (_magazines select 0) - 1) do {
			(unitBackpack _x) addMagazineCargoGlobal [(_magazines select 0) select _i,(_magazines select 1) select _i]; //return the magazines
		};
		for "_i" from 0 to (count (_weapons select 0) - 1) do {
			(unitBackpack _x) addWeaponCargoGlobal [(_weapons select 0) select _i,(_weapons select 1) select _i]; //return the weapons
		};
		for "_i" from 0 to (count (_items select 0) - 1) do {
			(unitBackpack _x) addItemCargoGlobal [(_items select 0) select _i,(_items select 1) select _i]; //return the items
		};
	};
} else {
	if ((backpack _x) != "b_parachute") then {_x addBackpack "B_parachute"}; //add the parachute if unit has no backpack
}} forEach units group player ;
{if (headgear _x != "H_CrewHelmetplane_B") then {_x addHeadgear "H_CrewHelmetplane_B"}} foreach units group player;
player moveInCargo planebase;
{ _x assignAsCargo (planeBase); _x moveIncargo (planeBase);} foreach units group player;
planebase flyinHeight 3000;
_HLPos = getMarkerPos "HALOdir_2";
_wp1 = planeTeam addWaypoint [( _HLPos), 0]; //Drop here
[planeTeam, 2] setWaypointBehaviour "Aware";
_wp1 setWaypointType "MOVE";
_wp1 setWaypointSpeed "NORMAL";
_wp1 setWaypointCombatMode "red";
_wp1 setwaypointstatements ["true", "{deleteVehicle _x} forEach (crew vehicle this) + [vehicle this]; deleteGroup group this"];
{waitUntil {isTouchingGround _x && alive _x};
_x setDamage 0} forEach units group player;

I refered myself to a couple of posts and the  Community Wiki but still fail to see a solution...

Thanks for the help!

Share this post


Link to post
Share on other sites
private _boatType = selectRandom ["CUP_B_RHIB2Turret_USMC","B_G_Boat_Transport_01_F"];
boatBase = _boatType createVehicle (getMarkerPos "Boatstart_3");
boatBase setDir (random 360);
player moveInDriver boatBase;
{ _x moveInAny (boatBase);} foreach units group player;

Try that, untested

Share this post


Link to post
Share on other sites
38 minutes ago, Zeraw said:

I'm struggling with a "variable not define" error for the variable boatBase :

You are using a global variable without a tag, any other script might overwrite or delete that variable at any time.
You should use a tag for global variables, like ZER_boatBase
Or just use local varibles where appropriate (like here)

Share this post


Link to post
Share on other sites

Ok thanks!

 

I'll try that and get back to you!

Share this post


Link to post
Share on other sites

You are not supplying a group/side for BIS_fnc_spawnVehicle, where in your original script you do ( planeTeam ).

This will cause no vehicle to be spawned, so _boatFrame1 will be an empty array, leading to boatBase being nil.

[
	getMarkerPos "Boatstart_3",
	random 360,
	selectRandom[ "CUP_B_RHIB2Turret_USMC", "B_G_Boat_Transport_01_F" ],
	side player
] call BIS_fnc_spawnVehicle params[ "_boat", "_crew", "_boatGroup" ];

//Delete spawned crew and their group
{
	_boat deleteVehicleCrew _x;
}forEach _crew;
deleteGroup _boatGroup;

player moveInDriver _boat;
{
	_x assignAsCargo _boat;
	_x moveInAny _boat;
}forEach ( units group player - [ player ] );

Also, you will most likely need to delete the spawned driver before moving the player into the drivers position.

EDIT: added to the above, included KK's suggestion.

 

Share this post


Link to post
Share on other sites

@Larrow sounds about right when I fiddled with

boatBase = _boatframe1 select 0;

It returned with an error "dividing by zero" as for an empty array.


thanks a lot!

Share this post


Link to post
Share on other sites

That's slick!

Never had tu use params before.
So, if I get it the returned value of the command you call before params are assigned to the variables you declared after it?

That's the script with the driver removed:
 

[
	getMarkerPos "HALOstart_3",
	random 360,
	selectRandom[ "CUP_B_RHIB2Turret_USMC", "B_G_Boat_Transport_01_F" ],
	side player
] call BIS_fnc_spawnVehicle params[ "_boat", "_crew", "_boatGroup" ];

{deleteVehicle _x} forEach crew (_boat);

player moveInDriver _boat;
{
	_x assignAsCargo _boat;
	_x moveInAny _boat;
}forEach ( units group player - [ player ] );

 

 

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

×