Jump to content
almaniak

Error Generic error in expression

Recommended Posts

So I've been bonking my head against the monitor for 2 days now because I can't figure out how to fix this.

CD_FNC_UpdateFlags =
{
private ["_zone", "_flag", "_flagTex", "_side"];

_zone = _this select 0;

_flag = FORMAT["P_Flag_%1",_zone];
_zVar = FORMAT["C_%1",_zone];
_side = missionNameSpace getVariable[_zVar,"independent"];
_flagO = missionNameSpace getVariable[_flag,nil];

if (_side == blufor) then {_flagTex = CD_NatoFlag};
if (_side == opfor) then {_flagTex = CD_CSATFlag} else { _flagTex = CD_AAFFlag};

_flagO setFlagTexture _flagTex;
};

Some context: The purpose of this script is that it will be called from an eventhandler (publicvarevent) and a string will be given as argument.

The script will(or should) automatically get the C_ZONENAME public variable and the P_Flag_ZONENAME flagpole object from the editor. Afterwards it checks the current value of C_ZONENAME for sides and assigns a flagtexture that is then assigned to the flag object.

However I'm constantly getting Error Generic error in expression. I've commented out line by line and sometimes I even get it with just _zone = _this select 0; :(

I'm calling the code with the debug menu and I've tried spawn and call. I even tried putting the function in a script and execVM/spawning the script but it all fails.

I've tried logging data, but that don't work cause the script fails before any lines get exec'd.

Is anyone here seeing what arma might be complaining about? the "Error Generic error in expression" error is really ambiguous and seems to not really give a specific line?

This is an example error I'm getting with this code:

0:26:59 Error in expression <", "_flagTex", "_side"];_zone = _this select 0 ;_flag = FORMAT["P_Flag_%1",_>

0:26:59 Error position: <select 0 ;_flag = FORMAT["P_Flag_%1",_>

0:26:59 Error Generic error in expression

I've looked up what Error Generic error in expression actually means but the explanation of "This error occurs when the type of data an operator is expecting does not match" does not seem to apply to my code? (unless I probably missed something?)

Any help would be greatly appreciated :D

Share this post


Link to post
Share on other sites

Looks like when you call it this line

_flagO = missionNameSpace getVariable[_flag,nil];

will have _flagO undefined if the missionnamespace actually returns nil,

which will lead to the error here:

_flagO setFlagTexture _flagTex;

would be my first guess.

Try to put an exitwith if the _flagO returns nil and see how that goes.

Second guess would be that _side returns independent and therefor _flagTex will not be defined, could lead to the same error in the setTexture line.

Cheers

Share this post


Link to post
Share on other sites

Maybe, but the error is before. I think he's calling the script in the wrong way

Share this post


Link to post
Share on other sites

As Giallustio said can you show us the calling code/publicvariable EH.

From what youve shown i would guess _this is not an ARRAY so select is throwing the error.

Share this post


Link to post
Share on other sites
How do you call it exactly?

The original idea was calling it via an eventhandler like this:

"C_TechCenter" addPublicVariableEventHandler {publicVariable"C_TechCenter";[CD_TechCenterStr] call CD_FNC_UpdateFlags;};

But I'm also trying to call it via the debugconsole with :

"TechCenter" spawn CD_FNC_UpdateFlags;

ExecVM when putting the code in scriptform makes no difference.

Looks like when you call it this line

_flagO = missionNameSpace getVariable[_flag,nil];

will have _flagO undefined if the missionnamespace actually returns nil,

which will lead to the error here:

_flagO setFlagTexture _flagTex;

would be my first guess.

Try to put an exitwith if the _flagO returns nil and see how that goes.

I tried that, making my code look like this:

CD_FNC_UpdateFlags =
{
private ["_zone", "_flag", "_flagTex", "_side"];

_zone = _this select 0;

_flag = FORMAT["P_Flag_%1",_zone];
_zVar = FORMAT["C_%1",_zone];
_side = missionNameSpace getVariable[_zVar,"independent"];
_flagO = missionNameSpace getVariable[_flag,nil];

       //New Exitwith
if (isNil "_flagO") exitWith {};

if (_side == blufor) then {_flagTex = CD_NatoFlag};
if (_side == opfor) then {_flagTex = CD_CSATFlag} else { _flagTex = CD_AAFFlag};

_flagO setFlagTexture _flagTex;
};

And I'm still getting;

17:23:58 Error position: <select 0;_flag = FORMAT["P_Flag_%1",_z>

17:23:58 Error Generic error in expression

(I'm not exactly sure that I used isNil correctly there so I tried with and without quotes for the variable)

Second guess would be that _side returns independent and therefor _flagTex will not be defined, could lead to the same error in the setTexture line.

If you check the script you see that it should have a default flag texture when side is independent at:

if (_side == opfor) then {_flagTex = CD_CSATFlag} else { _flagTex = CD_AAFFlag};

So I don't think thats where it breaks.

I've tested some more and after commenting out a huge chunk:

CD_FNC_UpdateFlags =
{
private ["_zone", "_flag", "_flagTex", "_side"];

_zone = _this select 0;

_flag = FORMAT["P_Flag_%1",_zone];
_zVar = FORMAT["C_%1",_zone];
/*
_side = missionNameSpace getVariable[_zVar,"independent"];
_flagO = missionNameSpace getVariable[_flag,nil];

if (isNil _flagO) exitWith {};
if (_side == blufor) then {_flagTex = CD_NatoFlag};
if (_side == opfor) then {_flagTex = CD_CSATFlag} else { _flagTex = CD_AAFFlag};
*/
//_flagO setFlagTexture _flagTex;
};

it still gives me the horrendous Lovecraftian error:

17:30:25 Error position: <select 0;_flag = FORMAT["P_Flag_%1",_z>

17:30:25 Error Generic error in expression

So I guess I really did something despicable with:

	private ["_zone", "_flag", "_flagTex", "_side"];

_zone = _this select 0;

_flag = FORMAT["P_Flag_%1",_zone];
_zVar = FORMAT["C_%1",_zone];

Unfortunately I can't figure out what. I've used this sort of string parsing before without any trouble :(

Appreciating the effort guys!

EDIT: I've found it! It was a combination of Larrow/Giallustio and Grumpy Old Man's answer, I already tried putting the variables in and out of brackets. Eg. ["RadioTower] and "RadioTower" but that didnt help me at first. However with Grumpy Old Man's exitwith it seems to have transcended to an executable state and it now works!

Thanks guys for all your help!

Edited by AlManiak

Share this post


Link to post
Share on other sites

Yeah you were right, I figured it out 10 minutes ago. I already tried with and without [] for the "RadioTower" parameter and at first it did not work (still got generic error), however with grumpy old man's exitWith and using [] it's now fully functional. Thanks for the help!:)

Share this post


Link to post
Share on other sites

I've got one of these if anyone can help:  if (_airClass == 0) then {__airTypes = _westAir};

 

Call

null = [0,0] execVM "randomAircraft.sqf";

Code

amb_fly_fn = compile preprocessFileLineNumbers "MPBIS_fnc_ambientFlyby.sqf";


// 1 = 0= WEST AIRCRAFT 1=EAST AIRCRAFT 2= IND AIRCRAFT
// 1 = 0= WESTSIDE 1=EASTSIDE 2= IND SIDE
// call is null = [0,0] execVM "randomAircraft.sqf";




private ["_airClass", "_airSide "];


_airClass  =  _this select 0;
_airSide  =  _this select 1;


if (_airClass == 0) then {_airClass = _westAir};
if (_airClass == 1) then {_airClass = _eastAir};
if (_airClass == 2) then {_airClass = _indAir};


if (_airSide == 0) then {_airSide = WEST};
if (_airSide == 1) then {_airSide = EAST};
if (_airSide == 2) then {_airSide = INDEPENDENT};


//get flyover centrepoint
_Pos = [getPos player,50,400,0,1,20,0] call BIS_fnc_findSafePos;


//get random spawn and despawn point
_dir1 = random 360;
_dir2 = _dir1 - 180;
_posA = [_pos, 3500, _dir1] call BIS_fnc_relPos; 
_posB = [_pos, 3500, _dir2] call BIS_fnc_relPos; 


// random airspeed
_speed = ["NORMAL", "FULL", "LIMITED"];
_speed1 = _speed call BIS_fnc_selectRandom;


// get random height
_height = [25, 50, 150, 250, 350, 450];
_height1 = _height call BIS_fnc_selectRandom;


//Pick a random Aircraft class
_westClass = ["B_Plane_CAS_01_F","B_Plane_CAS_01_F"];
_westAir = _westClass call BIS_fnc_selectRandom;
_eastClass = ["O_Plane_CAS_02_F","O_Plane_CAS_02_F"];
_eastAir = _eastClass call BIS_fnc_selectRandom;
_indClass = ["I_Plane_Fighter_03_AA_F","I_Plane_Fighter_03_CAS_F"];
_indAir = _indClass call BIS_fnc_selectRandom;


//do the thing
[_posA,_posB, _height1, _speed1, _airClass, _airSide, FALSE] spawn amb_fly_fn;


hint 'AirWarrrr!';

Share this post


Link to post
Share on other sites

 

I've got one of these if anyone can help:  if (_airClass == 0) then {__airTypes = _westAir};       __airTypes has got two underscores

 

Share this post


Link to post
Share on other sites

Doh! Really cleaned it all up a bit things are in the right place etc.

 

if (_airClass == 1) then {_airClass = _westAir} 
else {if (_airClass == 2) then {_airClass = _eastAir} 
else {if (_airClass == 3) then {_airClass = _indAir} 
else {_airClass = _westAir};
};
};


if (_airSide == 1) then {_airSide = WEST} 
else {if (_airSide == 2) then {_airSide = EAST} 
else {if (_airSide == 3) then {_airSide = INDEPENDENT} 
else {_airSide = WEST};
};
};

Share this post


Link to post
Share on other sites
switch (_airClass) do {
    case 1: { _airClass = _westAir };
    case 2: { _airClass = _eastAir };
    case 3: { _airClass = _indAir  };
    default { _airClass = _westAir };
};

switch (_airSide) do {
    case 1: { _airSide = WEST };
    case 2: { _airSide = EAST };
    case 3: { _airSide = INDEPENDENT };
    default { _airSide = WEST };
};

This would be even cleaner.

 

 

In addition I'd replace

_airClass =  _this select 0;
_airSide =  _this select 1;

with

_airClass = param [0,0];
_airSide = param [1,0];
  • Like 1

Share this post


Link to post
Share on other sites

BI already have some side enumerations that can make your life easy.

  • 0 = EAST
  • 1 = WEST
  • 2 = INDEP/GUER
  • 3 = CIV
These have functions that go with them for changing between side, number, color and type..

_side = 0 call BIS_fnc_sideType //EAST
_number = EAST call BIS_fnc_sideID //0
_color = EAST call BIS_fnc_sideColor //[0.5,0,0,1] - can also parse in the sideID 0
_type = 0 call BIS_fnc_sideName //"OPFOR" - can also parse in the sideID 0

For example...

amb_fly_fn = compile preprocessFileLineNumbers "MPBIS_fnc_ambientFlyby.sqf";

// call is null = ( side player )  execVM "randomAircraft.sqf";

params [
	[ "_airSide", west, [sideUnknown] ] //Default to WEST if a type of side [sideUnknown] is not parsed to the function
];

//get flyover centrepoint
_Pos = [getPos player,50,400,0,1,20,0] call BIS_fnc_findSafePos;

//get random spawn and despawn point
_dir1 = random 360;
_dir2 = _dir1 - 180;
_posA = [_pos, 3500, _dir1] call BIS_fnc_relPos; 
_posB = [_pos, 3500, _dir2] call BIS_fnc_relPos; 

// random airspeed
_speed = ["NORMAL", "FULL", "LIMITED"] call BIS_fnc_selectRandom;

// get random height
_height = [25, 50, 150, 250, 350, 450] call BIS_fnc_selectRandom;

//Pick a random Aircraft class
_airClass = ( [
	["O_Plane_CAS_02_F","O_Plane_CAS_02_F"],	//EAST
	["B_Plane_CAS_01_F","B_Plane_CAS_01_F"],	//WEST
	["I_Plane_Fighter_03_AA_F","I_Plane_Fighter_03_CAS_F"]	//INDEP/GUER
] select ( _airSide call BIS_fnc_sideID )) call BIS_fnc_selectRandom;	//Select inner array based on sideID, select a random one from inner array

//do the thing
[_posA,_posB, _height, _speed, _airClass, _airSide, FALSE] spawn amb_fly_fn;

hint 'AirWarrrr!';
  • Like 1

Share this post


Link to post
Share on other sites

Thanks Larrow, that's quality. Makes it so much more versatile as I can randomise the sides as well and just have ambient aircraft buzzing around on loop and timer without cluttering up the mission

 

The basic version is finished I think. Here it is if anyone wants some AA target pratice. I'm going to finish what I started and see how much I can smash up the BIS Ambient flyby function.  :)

 

amb_fly_run = true;


while {amb_fly_run} do { 


//params
private ["_airSide","_centre", "_rtime ","_setCaptive"];


_airSide = param [0,west, [sideUnknown]];
_centre = param [1,player, [objNull]];
_setCaptive = param [2,TRUE, [TRUE]];
_rtime = param [3,240,[0]];


//get flyover centrepoint
_Pos = [getPos _centre,50,400,0,1,20,0] call BIS_fnc_findSafePos;


//get random spawn and despawn point
_dir1 = random 360;
_dir2 = _dir1 - 180;
_posA = [_pos, 3500, _dir1] call BIS_fnc_relPos; 
_posB = [_pos, 3500, _dir2] call BIS_fnc_relPos; 


// random airspeed
_speed = ["NORMAL", "FULL", "LIMITED"] call BIS_fnc_selectRandom;


// get random height
_height = [25, 50, 150, 250, 350, 450] call BIS_fnc_selectRandom;


//Pick a random Aircraft class
_airClass = ( [
["O_Plane_CAS_02_F","O_Heli_Light_02_F","O_Heli_Light_02_unarmed_F","O_Heli_Light_02_v2_F","O_Heli_Attack_02_F","O_Heli_Attack_02_black_F","O_Heli_Transport_04_medevac_black_F","O_Heli_Transport_04_repair_F"], //EAST
["B_Plane_CAS_01_F","B_Heli_Light_01_F","B_Heli_Light_01_armed_F","B_Heli_Attack_01_F","B_Heli_Transport_01_F","B_Heli_Transport_01_camo_F","B_Heli_Transport_03_F","B_Heli_Transport_03_unarmed_F","B_Heli_Transport_03_black_F"], //WEST
["I_Plane_Fighter_03_AA_F","I_Heli_Transport_02_F","I_Heli_light_03_F","I_Heli_light_03_unarmed_F","I_Plane_Fighter_03_CAS_F"] //INDEP/GUER
] select ( _airSide call BIS_fnc_sideID )) call BIS_fnc_selectRandom; //Select inner array based on sideID, select a random one from inner array


//do the thing
//[_posA,_posB, _height, _speed, _airClass, _airSide, _setCaptive] spawn amb_fly_fn;
[_posA,_posB, _height, _speed, _airClass, _airSide] call BIS_fnc_ambientFlyBy;


//Debug Hint
hint format["Unit is going %1 speed, is a %2 at %3 metres on heading %4",_speed, _airClass,_height, _dir2];


sleep (60 + (random _rtime));


};
//Debug Hint
//hint 'loop stopped';

Share this post


Link to post
Share on other sites

What does

_airSide = param [0,west, [sideUnknown]]; 

sideUnknown mean?

Share this post


Link to post
Share on other sites

Just another side type, if a soldier knows another exist but has not been close enough to distinguish its side then it will report it as sideUnknown. I just use it for my params in the same way as i would use objNull or grpNull, its a certain data type but it has no distinguishable information.

  • Like 1

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

×