Error generic error in expression

So Ive been bonking my head against the monitor for 2 days now because I cant 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...

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 July 8, 2015 by AlManiak

Table of Contents

ArmA 2 Common Scripting Errors

Error Generic Error in Expression

This error occurs when the type of data an operator is expecting does not match.

Example:

_myString = "The meaning of life is " + 42

Error Invalid Number in Expression

This usually occurs when an expression is left incomplete or malformed.

Example:

_myNumber = 2 + 3 +

Error Type Something Expected Nothing

This error usually occurs when a statement is incomplete, malformed, or non-existent.

Examples:

non-existent statement:

7 + 6 * 5

malformed statement:

3 = 4

incomplete statement:

_myVariable

Error Type String Expected Code

This error occurs when there is a syntax error contained inside a block of code that makes up part of another statement. The error will be identified as being part of the original statement, not on the specific line where it actually occurs. For instance, if there is a syntax error inside an if statement’s “then” block or “else” block, the error will be identified in front of the “then” keyword or “else” keyword respectively.

Example:

if (_USD + _USDcent + _CAD + _CADcent + _ZWD == 0) then
{
	hint "Your wallet is empty.";
}
else
{
	_output = "Your wallet contains:";
	if (_USD+_USDcent > 0) then
	{
		_output = _output + format["n- United States Dollars: %1.%2 USD", _USD, _USDcent];
	} <-- Missing semicolon
	if (_CAD+_CADcent > 0) then
	{
		_output = _output + format["n- Canadian Dollars: %1.%2 CAD", _CAD, _CADcent];
	} <-- Missing semicolon
	if (_ZWD > 0) then
	{
		_output = _output + format["n- Zimbabwean Dollars: %1 ZWD", _ZWD];
	} <-- Missing semicolon ...
	hint _output;
};

There are missing semicolons on each of the if statements within the else block, but the error will be identified as being before the “else” statement as “Type String, Expected Code”.

Error Unknown Operator

This error occurs when the game engine has attempted to parse something as an operator, but could not successfully find the given symbol.

Examples:

_myBits = 1002 | 43
_myVariable = "hello " concat "world!"

There are several reasons why this might happen. If a script intended for a new version of OFP makes use of a new operator, and is run on an old copy of the game, this error will show up. Another common cause is when executing a formatted String as an instruction, where a variable inside the instruction is undefined.

Example:

["a = %1", b]

Outputted instruction:

a = scalar bool array string 0xfcfffef

Result:

The engine interprets ‘scalar’ as an uninitialised variable (similar to ‘b’ in the above example), and the parser expects an operator as the next token. ‘bool’ cannot be found in the list of operators (since it isn’t one), and so an Unknown Operator message is given.

Error Zero Divisor

This error occurs when the variable you are trying to divide has a value of zero, or when you attempt to divide a variable by 0. It also occurs when you attempt to access an element of an array which does not exist.

Example:

_myVar = 0 / 15
_myVar = 15 / 0
_myVar = [1,2,3] select 15

When an error makes no sense

Sometimes, the displayed error will not appear to be correct. The error parser will point you to a line of code which is correct, yet it will tell you that some strange error exists at that point.

In this case, the problem usually lies beneath that point in the code. Usually the source of the error is actually a missing parenthesis, bracket, curly brace, etc. Usually the error message says that it encountered a string where it expected code.

Example:

for "_i" from 0 to 1 do
{
	_str = format["mystring";
};

In this example, the error will be shown to originate just to the left of the word “do”. However, the error is actually caused by a line in the code beneath the do statement. (Such an error would be difficult to spot if it were many more lines down in the code.)

scalar bool array string 0xe0ffffef

If variables don’t exist, their value as string is generally a “scalar bool array string 0xe0ffffef” error.

Examples:

hint format ["%1", undefined_variable]
 
hint (if (format ["%1", undefined_variable] == "scalar bool array string 0xe0ffffef") then [{"Variable undefined"},{"Variable already defined"}])

Добрый вечер, большое количество сообщение о данной ошибке у клиента, что может быть?

 Error position: <!= '0'))then
{
_vehcolor = [0.7,0,0,1];
>
  Error Generic error in expression
Error in expression <','0'];
if((MOD_EPOCH) && (_characterID != '0'))then
{
_vehcolor = [0.7,0,0,1];
>
  Error position: <!= '0'))then
{
_vehcolor = [0.7,0,0,1];
>
  Error Generic error in expression
Error in expression <','0'];
if((MOD_EPOCH) && (_characterID != '0'))then
{
_vehcolor = [0.7,0,0,1];
>
  Error position: <!= '0'))then
{
_vehcolor = [0.7,0,0,1];
>
  Error Generic error in expression
Error in expression <','0'];
if((MOD_EPOCH) && (_characterID != '0'))then
{
_vehcolor = [0.7,0,0,1];
>
  Error position: <!= '0'))then
{
_vehcolor = [0.7,0,0,1];
>
  Error Generic error in expression
Error in expression <','0'];
if((MOD_EPOCH) && (_characterID != '0'))then
{
_vehcolor = [0.7,0,0,1];
>
  Error position: <!= '0'))then
{
_vehcolor = [0.7,0,0,1];
>
  Error Generic error in expression
Error in expression <','0'];
if((MOD_EPOCH) && (_characterID != '0'))then
{
_vehcolor = [0.7,0,0,1];
>
  Error position: <!= '0'))then
{
_vehcolor = [0.7,0,0,1];
>
  Error Generic error in expression

Oubi, преимущества:
1. Явное указание пространства имен в котором нужна ваша переменная:

// init.sqf
MyVariable = 1;
// В каком-то скрипте
MyVariable; // 1
// В каком-то другом скрипте
MyVariable; // nil

Разница между скриптами в том, например, что первый был вызван из триггера, а второй из UI, где часто встречается следующая конструкция смены пространства имен:

with uiNamespace do { ... };

А использовав вместо обычного имени переменной следующую конструкцию:

missionNamespace getVariable "MyVariable";

Вы бы всегда получали нужное значение, независимо от контекста выполнения
2. По-умолчанию всегда используется missionNamespace, с помощью команды with-do, упомянутой выше, вы можете сменить пространство имен на uiNamespace, parsingNamespace или profileNamespace. Но с помощью setVariable/getVariable вы можете использовать в качестве пространства имен почти любой объект в Арме! Тем самым реализуя концепцию Объектно-ориентированного программирования:

{ _x setVariable ["MyVariable", _forEachIndex]; } forEach [unit1, unit2, unit3];
unit1 getVariable "MyVariable"; // 0
unit2 getVariable "MyVariable"; // 1
unit3 getVariable "MyVariable"; // 2
MyVariable; // nil

3. in-engine проверка на определение переменной:

MyVariable; // nil
if (isNil "MyVariable") then { 1; } else { MyVariable; }; // 1

Или просто:

missionNamespace getVariable "MyVariable"; // nil
missionNamespace getVariable ["MyVariable", 1]; // 1

4. Т. к. для указания переменной вам нужно ее название в типе STRING, то это позволяет генерировать имя переменной:

{ missionNamespace setVariable [format ["unit%1", _forEachIndex], _x]; } forEach allUnits;

Теперь каждый юнит имеет переменную ссылающуюся на него с именем unit + индекс. Хоть этот код полностью бесполезен, но попробуйте тоже самое провернуть, когда у вас 100 юнитов, без помощи setVariable… у вас банально закончится терпение на 5 или 10 юните!
Так же это позволяет использовать передачу аргументов по «ссылке». Хоть в SQF все переменные и передаются по ссылке, но из-за особенностей реализации команд модифицируются по ссылке только массивы. А иногда нужно модифицировать и другие типы данных:

MyVariable = ""; // ""
[missionNamespace, "MyVariable"] call MyFunction;
MyVariable; // "Hello world!";
// MyFunction
params ["_namespace", "_variable"];

_namespace setVariable [_variable, "Hello world!"];

5. Sharing значения переменной в сетевой игре. Часто можно увидеть следующую конструкцию:

MyVariable = 1;
publicVariable "MyVariable";

Это отправка значения переменной всем другим клиентам в сетевой игре. Но это можно сделать только для переменных в missionNamespace, в то время как с помощью setVariable это можно сделать для переменных практически в любом пространстве:

unit1 setVariable ["MyVariable", 1, true];

И через некоторое время, когда переменная будет синхронизирована, на других машинах в сети можно будет получить:

unit1 getVariable "MyVariable"; // 1

6. Обычная переменная накладывает на свое имя следующие ограничения: только латинские буквы, цифры и нижнее подчеркивание, первый символ не цифра. Имя переменной задаваемой и получаемой с помощью этих команд может быть любым:

missionNamespace setVariable ["This is my variable!", 1];
missionNamespace getVariable "This is my variable!"; // 1
This is my variable! = 1; // Error Missing ;

7. Имя переменной будет проверено на совпадение с зарезервированными именами и выведется понятное сообщение:

missionNamespace setVariable ["player", 1]; // Error Reserved variable in expression
player = 1; // На клиента: Error Generic error in expression На выделенном сервере может вообще ничего не написать

Недостатки: Он всего один — скорость:

Result:
0.0004 ms

Cycles:
10000/10000

Code:
MyVariable
Result:
0.0007 ms

Cycles:
10000/10000

Code:
missionNamespace getVariable "MyVariable"
Result:
0.0016 ms

Cycles:
10000/10000

Code:
missionNamespace getVariable ["MyVariable", 1]

Но тут стоит сказать одну вещь: доступ к локальным переменным значительно быстрее доступа к глобальным переменным:

Result:
0.0003 ms

Cycles:
10000/10000

Code:
_myVariable

Из чего вытекает следующее:

Result:
0.0549 ms

Cycles:
10000/10000

Code:
for "_i" from 0 to 99 do { MyVariable; }
Result:
0.044 ms

Cycles:
10000/10000

Code:
private _MyVariable = missionNamespace getVariable ["MyVariable", 1]; for "_i" from 0 to 99 do { _MyVariable; }

Сообщение отредактировал vlad333000: 18 December 2018 — 22:59

Понравилась статья? Поделить с друзьями:
  • Error generating ku from authentication pass phrase
  • Error gen invalid gta 5
  • Error gc106 блок страйк
  • Error gateway timeout mikrotik httpproxy
  • Error gaster wiki