Jump to content
Sign in to follow this  
wiggum2

Is there anything why || or OR should not work ?

Recommended Posts

Hi,

i have a problem with a trigger...

In the condition field i put:

free OR dead

But the trigger only fires if dead is true !

I also tried

free || dead

and it dosent work to.

Did i miss something here ?

Share this post


Link to post
Share on other sites

no, you didn't. Boolean algebra is hardly rocket science, so I guess the variable "free" simply doesn't switch to true. But you could have checked that by yourself easily.

There is nothing anyone here could do for you, unless you post what's really happening in your mission.

Share this post


Link to post
Share on other sites

Mhhhh...

I always thought you dont have to set variables to false manually...

I thought its enough to make "free=true" in a trigger and thats all.

But that way it dont worked for me !

If set free to false in the init.sqf and then to true with a trigger later ingame the other trigger fires like he should.

Share this post


Link to post
Share on other sites

do what i do, when something is in question settup a radio command setting it to true and a hint just for a test...

Share this post


Link to post
Share on other sites
do what i do, when something is in question settup a radio command setting it to true and a hint just for a test...

I did such testing too.

Like i sayed, problem is solved by setting free to false in the init.sqf !

Share this post


Link to post
Share on other sites
Mhhhh...

I always thought you dont have to set variables to false manually...

I thought its enough to make "free=true" in a trigger and thats all.

But that way it dont worked for me !

Well, there is your problem. If you don't initialize your variables, they won't exist. Thus if you try to access what doesn't exist, you will get nil. Nil is defined as "nothing" which does not equal anything - not even false. It's nil.

Now you may either initialize your variables (init.sqf) or you may alter your condition expression and check if the variable exists (isnil) or not. Though I strongly suggest you settle for the first solution, thus checking variables that are guaranteed to be boolean instead of checking if there is any variable at all - regardless of it's type...

Share this post


Link to post
Share on other sites

All variables in a condition need to be defined. Even missing one variable in a "OR" condition will break the whole condition. This is because Arma doesn't use/support lazy evaluation. Instead it checks the whole condition at once.

Share this post


Link to post
Share on other sites

I got into another OR madness today... :(

(e2 knowsAbout p0 > 1) || (e2 knowsAbout p1 > 1)

Does not work...

(e2 knowsAbout p0 > 1)

Does work...

(true) || (true)

Does work...

(e2 knowsAbout p0 > 1 is true in both examples, e2 knowsAbout p1 > 1 is always false)

But why does the first code not work as condition (tested with hint) and the second one works perfecly ?

Any other way to set up a trigger who checks if e2 knowsAbout p0 or p1 ?

Share this post


Link to post
Share on other sites

if ((e2 knowsAbout p0 > 1) || (e2 knowsAbout p1 > 1)) then {

Should work just fine. Your problem is something else.....not the "||"

Share this post


Link to post
Share on other sites

Works not for me...

And im sure that everything else is correct.

((e2 knowsAbout p0 > 1) || (e2 knowsAbout p1 > 1))

Dont works for me as Condition inside a trigger.

Share this post


Link to post
Share on other sites

Works fine inside a trigger for me with....

this && ((e2 knowsAbout p0 > 1) || (e2 knowsAbout p1 > 1))

Share this post


Link to post
Share on other sites

Looks like i deleted unit p1 unintentionally and thats why the trigger not worked... :confused:

I created unit p1 again and now it works !

Share this post


Link to post
Share on other sites
I always thought you dont have to set variables to false manually...

I think that used to be the case with Arma1, but now you have to initialize.

Share this post


Link to post
Share on other sites
I think that used to be the case with Arma1, but now you have to initialize.

It was never the case, but it depends. If you're using a simple one-variable switch, then you don't need to set that variable to false before it is set to true. Before it's set to true, the result of the condition will be undefined, so the trigger or conditional statement won't fire anyway. Once you set it to true, it becomes defined and now the trigger or conditional statement will fire. The problem arises when using logical operators like OR, AND, etc. If you have true OR undefined, the result is still undefined, so the trigger or conditional statement still won't fire.

In general, it's a good practice to simply define all variables that you intend to use. Less headache this way.

Share this post


Link to post
Share on other sites

Thanks fpor the advise !

Just a quick question (this drives me nuts!):

_unit      = _this select 0;
_areaname  = _this select 1;
_areasize  = _this select 2;
_grphunter = _this select 3;
_grptarget = _this select 4;
_delay     = _this select 5;

_eastmen = nearestobjects [_areaname,["SoldierEB"],_areasize];
_westmen = nearestobjects [_areaname,["SoldierWB"],_areasize];

_patrol = [_unit, position _unit, 300, 7, "MOVE", "SAFE", "RED", "LIMITED", "STAG COLUMN", "", [2,5,10]] call CBA_fnc_taskPatrol;
hint "Patroling";

while {
   ({alive _x} count units _grphunter > 0) &&
   ({_x knowsAbout ({_x} forEach _westmen) <= 1.3} count _eastmen > 0)
     } do {
sleep 1;
hint "test";

{ 
_temp = _x;
{_temp reveal _x}  foreach _westmen;
} foreach  _eastmen;

sleep 5;

if [color="Blue"]([/color]({_x knowsAbout ({_x} forEach _westmen) > 1.3} count _eastmen > 0) [color="Blue"]&& ({alive _x} count units _grptarget > 0))[/color]  [color="Red"]then {[/color]

hint format ["west %1 east %2",count _westmen,count _eastmen];
sleep 2;
terminate _patrol;
hint "Stop patrol";
{_x setBehaviour "AWARE"; _x setCombatMode "RED"; _x setSpeedMode "FULL"} foreach units _grphunter;

_delay = (if (count _this > 2) then {_this select 5} else {10});
_grphunter move getpos leader _grptarget;
sleep _delay;
hint "hunting";
 };
};

Everything after the red then does not work.

But if i delete the blue marked stuff it works...

So there is a problem with:

({alive _x} count units _grptarget > 0)

But what the hell should be wrong with that ?

_grptarget = mygroup and mygroup leader has "mygroup = group this" in his init and is alive !

And the enemy has in his init:

nul=[this,this,1500,group this,mygroup,5] execVM "patrolhunt.sqf";

Edited by Wiggum

Share this post


Link to post
Share on other sites

Are you sure that's the part of the script that's not working? The first half of that condition looks much more problematic; the way you're using forEach within a count condition like that shouldn't work AFAIK. Try it with just the {alive _x}... part and see what happens. If that doesn't work, then _grptarget isn't being defined properly for whatever reason.

Share this post


Link to post
Share on other sites

I tested it and it seems to work, sort of.

The problem is they start to hunt but give up a second later, they move to the first contact point though.

the problem is here ({_x knowsAbout ({_x} forEach _westmen) <= 1.3} count _eastmen > 0) set to !=0 and they do indeed hunt.

I posted the amended code in the other link.

I'm not saying that is right but it's getting them moving at least.

I see you also got a bit further anyway.

Edited by F2k Sel

Share this post


Link to post
Share on other sites

Here is my fixed version:

patrolhunt.sqf:

_unit      = _this select 0;
_patrolpos = _this select 1;
_areaname  = _this select 2;
_areasize  = _this select 3;
_grphunter = _this select 4;
//_grptarget = _this select 4;
_delay     = _this select 5;

_eastmen = nearestobjects [_areaname,["SoldierEB"],_areasize];
_westmen = nearestobjects [_areaname,["SoldierWB"],_areasize];

_patrol = [_unit, position _patrolpos, 300, 7, "MOVE", "SAFE", "RED", "LIMITED", "STAG COLUMN", "", [2,5,10]] call CBA_fnc_taskPatrol;
hint "Patroling";

while {
   ({alive _x} count units _grphunter > 0) &&
   ({_x knowsAbout ({_x} forEach _westmen) <= 1.3} count _eastmen > 0)
     } do {
sleep 1;
hint "test";

{ 
_temp = _x;
{_temp reveal _x}  foreach _westmen;
} foreach  _eastmen;

sleep 5;

if (({_x knowsAbout ({_x} forEach _westmen) > 1.3} count _eastmen > 0) && ({alive _x} count units mygroup > 0)) then {

hint format ["west %1 east %2",count _westmen,count _eastmen];
sleep 2;
terminate _patrol;
hint "Stop patrol";
{_x setBehaviour "AWARE"; _x setCombatMode "RED"; _x setSpeedMode "FULL"} foreach units _grphunter;

_delay = (if (count _this > 2) then {_this select 5} else {10});
_grphunter move getpos leader mygroup;
sleep _delay;
hint "hunting";

   };

if ({alive _x} count units mygroup == 0) then {
_grphunter move getpos _patrolpos;
_patrol = [_unit, position _patrolpos, 300, 7, "MOVE", "SAFE", "RED", "LIMITED", "STAG COLUMN", "", [2,5,10]] call CBA_fnc_taskPatrol;
hint "Patroling";
 };
};

Everything works but i would like to be able to set more then one group as "_grptarget" !

Currently only one is possible, can someone help ?

Share this post


Link to post
Share on other sites

Are you getting any script errors? I can't see why the local variable wouldn't work in this case.

Share this post


Link to post
Share on other sites

No errors, it just dont works with "_grptarget"...but works with "mygroup"...

I really would like to know why...

I think it has something to do with the enemy groupleader init:

nul=[this,this,1500,group this,mygroup,5] execVM "patrolhunt.sqf";

And inside the script:

_grptarget = _this select 4;

Edited by Wiggum

Share this post


Link to post
Share on other sites

My best guess would be that the script is being called before mygroup has been set, so _grptarget is undefined. Try adding a one second sleep to the very beginning of your script (before the local variables are assigned). If this fixes the problem, then you know that was the issue.

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  

×