Jump to content
Sign in to follow this  
bigshotking

Generic Error in Expression Help

Recommended Posts

I made this little function for one of my missions, it spawns a helicopter, attaches a pre-placed vehicle under it then flies to the designated location and drops it off. For some reason though it refuses to work, in-game I keep getting an error on the line highlighted in red:

createEnemyTransport = {  

if(!isServer) exitWith {};

private ["_pos","_veh","_pilot","_vehicle","_prototype"];

_pos = _this select 0;

eastGRP = createGroup East; 
_veh = createvehicle ["Mi17_TK_EP1",[_pos select 0, _pos select 1,0], [],0,"FLY"];
_veh flyinHeight 100;
_pilot = eastGRP createunit ["TK_Soldier_Pilot_EP1", [0,0,1], [], 0, "CAN_COLLIDE"];
_pilot moveInDriver _veh;
_pilot flyInHeight 100;

   if (!(isEngineOn _veh)) then {
       _veh engineOn true;
  	};

_vehicle = _pos nearEntities [["BMP2_HQ_INS"],500];
_prototype = _vehicle select 0;
_prototype attachTo [_veh,[0,0,-5]];

   _veh doMove (getMarkerPos "obj");
_veh flyinHeight 100;
waitUntil {moveToCompleted _veh};
_veh land "LAND";
_veh flyinHeight 0;
waitUntil {((position _veh) select 2) < 10};
detach _prototype;

if (DEBUG) then {
	server globalChat format ["%1 created", _type];  
};
};

[color="#FF0000"]waitUntil {((position _veh) select 2) < 10};[/color]

Here is the piece for the .RPT:

Error in expression <obj");
_veh flyinHeight 100;
waitUntil {moveToCompleted _veh};
_veh land "LAND";>
 Error position: <moveToCompleted _veh};
_veh land "LAND";>
 Error Generic error in expression
Suspending not allowed in this context
Error in expression <;
waitUntil {((position _veh) select 2) < 10};
detach _prototype;

if (DEBUG) the>
 Error position: << 2};
detach _prototype;

if (DEBUG) the>
 Error Generic error in expression

Can anyone shed some light onto why this is happening?

Thanks in advance,

-Bigshot

Share this post


Link to post
Share on other sites

Functions should not contain sleep or waituntil. Use spawn as cuel suggests.

Share this post


Link to post
Share on other sites

Hmmm ok I'll edit the script to include spawn and try that out. I'll be sure to post the result when I can. Thanks

---------- Post added at 04:49 AM ---------- Previous post was at 03:54 AM ----------

Ok I updated the script, no more errors are given. I'm calling the function like this:

[getMarkerPos "obj"] call createEnemyTransport;

Here is the updated function, but still having issues. The helicopter spawns, but it immediately lands and sits on the ground doing nothing. Also for some reason the vehicle is not attached either.

createEnemyTransport = {  

if(!isServer) exitWith {};

private ["_pos","_veh","_pilot","_vehicle","_prototype"];

_pos = _this select 0;

eastGRP = createGroup East; 
_veh = createvehicle ["Mi17_TK_EP1",[_pos select 0, _pos select 1,0], [],0,"FLY"];
_veh flyinHeight 100;
_pilot = eastGRP createunit ["TK_Soldier_Pilot_EP1", [0,0,1], [], 0, "CAN_COLLIDE"];
_pilot moveInDriver _veh;
_pilot flyInHeight 100;

   if (!(isEngineOn _veh)) then {
       _veh engineOn true;
  	};

_vehicle = _pos nearEntities [["BMP2_HQ_INS"],500];
_prototype = _vehicle select 0;
_prototype attachTo [_veh,[0,0,-5]];

   _veh doMove (getMarkerPos "obj");
_veh flyinHeight 100;
[] spawn {
	waitUntil {moveToCompleted _veh};
};
_veh land "LAND";
_veh flyinHeight 0;
[] spawn {
	waitUntil {((position _veh) select 2) < 10};
};
detach _prototype;

if (DEBUG) then {
	server globalChat format ["%1 created", _type];  
};
}; 

Any ideas why this is happening?

Share this post


Link to post
Share on other sites

Using spawn, you spawn a new thread. It does not contain any local variables from where you spawned it, those needs to be passed over. Your function will also not wait for the spawn to complete.

_veh = createvehicle ["Mi17_TK_EP1",[_pos select 0, _pos select 1,0], [],0,"FLY"]; 
[]spawn {deleteVehicle _veh};

_veh does not exist in the spawn.

_veh = createvehicle ["Mi17_TK_EP1",[_pos select 0, _pos select 1,0], [],0,"FLY"]; 
_veh spawn {deleteVehicle _this};

Makes sense?

Try changing your call function to

[getMarkerPos "obj"] spawn createEnemyTransport;  

And delete the spawn inside your function.

Share this post


Link to post
Share on other sites

Thanks for the clarification, seems silly now the way I had it.

I finally got it working but had to put a handle on it:

null = [getMarkerPos "obj"] spawn createEnemyTransport;

Thanks for the help guys!

-Bigshot

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
Sign in to follow this  

×