Home   Help Search Login Register  

Author Topic: Undefined Variable script error. Trigger v.s script  (Read 3423 times)

0 Members and 1 Guest are viewing this topic.

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Undefined Variable script error. Trigger v.s script
« on: 05 Sep 2009, 22:02:54 »
Hi all,

Turning on -showScriptErrors was an interesting thing  :blink:

My experience is that a script checking for a variable, as in - if, waitUntil, ? or @ is very picky.
If the variable definition isn't timed perfectly and is a second too late, there is a reported error.

Triggers however, seem to work as before, meaning they can have a condition which waits for an undefined variable, but no error is reported.

Is this true, does anyone know for sure?

Laggy
« Last Edit: 05 Sep 2009, 22:46:48 by laggy »
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Undefined Variable script error. Trigger v.s script
« Reply #1 on: 05 Sep 2009, 22:38:12 »
this might happen with globals that defined somewhere and checked by some other script. Best option is to defined them with a default value in init.sqf, or use

Code: [Select]
if (!isNil "namevar") then
{
   if (namevar == 32) then
   {
   };
};

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: Undefined Variable script error. Trigger v.s script
« Reply #2 on: 05 Sep 2009, 22:47:06 »
Thanks Mandoble,

Confirmed in testing,

myVar is undefined.

if (myVar) then {hint "Variable test"}; - No error in a trigger, but error reported if checked in a script.

Laggy
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Shuko

  • Members
  • *
Re: Undefined Variable script error. Trigger v.s script
« Reply #3 on: 06 Sep 2009, 02:23:35 »
That's how it is, indeed.

Offline DeanosBeano

  • Addons Depot Staff
  • *****
  • SirDeanosbeano bstowed on me by sui ;)
    • Fraghaus
Re: Undefined Variable script error. Trigger v.s script
« Reply #4 on: 06 Sep 2009, 11:02:16 »
 It was anounced way back from Maruk that this will be the case for arma2 as a difference,

 
Quote
ArmA 2 will be laregerly compatible with Armed Assault. To make porting of content from ArmA as simple as possible.

Currently, one of the most important things is:

* using of undefined variable in scripts (nil value) will be in ArmA 2 strictly reported as an error. All variables used in any scripts must be initialized before first use.

 I hope thats what your talking about here :),
I love ofp

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: Undefined Variable script error. Trigger v.s script
« Reply #5 on: 06 Sep 2009, 11:29:22 »
Yes,

I guess I was surprised that the triggers still accept undefined variables.
Could be good to know.

Laggy
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Shuko

  • Members
  • *
Re: Undefined Variable script error. Trigger v.s script
« Reply #6 on: 06 Sep 2009, 18:54:56 »
You can call undefined preprocessed scripts (var = compile preprocessfile) in triggers on Act and you will not get an error, it just doesn't work. So, careful not to make typos in those. :)

Offline jones

  • Members
  • *
Re: Undefined Variable script error. Trigger v.s script
« Reply #7 on: 10 Sep 2009, 05:52:30 »
I have been getting the undefined error despite the fact that the variable is defined and it shows up in a hint with the value. Despite the error the script works it just fills the rpt file up with that dang on error.

I am trying to propagate the knows about factor of the unit's targets through out the other groups. The script works it is just that dang on error pops up.

the error occurs at "_leader knowsabout" and  "leader reveal _x" _leader being the undefined variable that is actually defined......

EDIT: I was playing around with the script and some of the groups were returning as null, that might be the problem but when i try to exlude them from the array with if (!isnull blah blah)... it stil adds null objects to the array. I am getting a tumor from this.
would appreciate any insight anyone may have on this.

Code: [Select]
private ["_unitleaders","_allgroups","_allgrpcnt","_targetarray","_enemyunits","_allunits","_allcount","_leader","_intel"];
_unitleaders = [];
_allgroups = allgroups;
_allgrpcnt = count _allgroups;
for [{_i=0}, {_i<_allgrpcnt}, {_i=_i+1}] do
{
_checkunit = _allgroups select _i;
if (side _checkunit == west)then
{
_leader = leader _checkunit;
_unitleaders set [_i,_leader];
};
};
_targetarray = [];
_enemyunits = [];
_allunits = allunits;
_allcount = count _allunits;

for [{_i=0}, {_i<_allcount}, {_i=_i+1}] do
{
_checkunit = _allunits select _i;
if (side _checkunit == east)then
{
_enemyunits set [_i,_checkunit];
}
};

_count = 0;
{
if (alive _x) then
{
for [{_i=0}, {_i<_allgrpcnt}, {_i=_i+1}] do
{
_leader = _unitleaders select _i;
hintsilent format ["%1",_leader];
_intel = _leader knowsabout _x;
if (_intel > 1)then
{
_targetarray set [_count,_x];
_count = _count + 1;
};
};
};
} foreach _enemyunits;

{
for [{_i=0}, {_i<_allgrpcnt}, {_i=_i+1}] do
{
_leader = _unitleaders select _i;
_leader reveal _x;
};
} foreach _targetarray;
« Last Edit: 10 Sep 2009, 09:28:44 by jones »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Undefined Variable script error. Trigger v.s script
« Reply #8 on: 10 Sep 2009, 10:41:20 »
More than problably _allgroups has some undefined member. For example, lets say allgroups = [grp1, grp2, grp3] and grp2 has not been assigned or defined, then you will have that error even with the allgroups array defined. This rule probably applies to variables and also array contents.

Offline dr. seltsam

  • Members
  • *
Re: Undefined Variable script error. Trigger v.s script
« Reply #9 on: 10 Sep 2009, 14:01:20 »
I'm not sure with Arma2, but i say:

private ["_unitleaders","_allgroups","_allgrpcnt","_targetarray","_enemyunits","_allunits","_allcount","_leader","_intel","_x"];

:)

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Undefined Variable script error. Trigger v.s script
« Reply #10 on: 10 Sep 2009, 14:46:20 »
You should not define "_x" there, _x is a special internal var used by ArmA and ArmA2 just for forEach command.

Offline jones

  • Members
  • *
Re: Undefined Variable script error. Trigger v.s script
« Reply #11 on: 10 Sep 2009, 19:41:04 »
The allgroup returns all kinds of strange stuff. I went back to square one and revised the script to build the groups and insert them into an array. Then I pulled the group leaders from that array. No errors now.