Home   Help Search Login Register  

Author Topic: Limited code in triggers ?  (Read 1359 times)

0 Members and 1 Guest are viewing this topic.

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Limited code in triggers ?
« on: 10 May 2009, 17:20:32 »
Can anyone tell me why some variable conditions are possible in scripts but not triggers ?

For example, I have allways wondered why this works as trigger condition:
Code: [Select]
myVar1 AND myVar2 AND myVar3 AND myVar4 AND myVar5 etc.
Also.
Code: [Select]
myVar1 OR myVar2 OR myVar3 OR myVar4 OR myVar5 etc.
But not this:
Code: [Select]
myVar1 AND myVar2 AND (myVar3 OR myVar4 OR myVar5)
Another thing that works in scripts is:
Code: [Select]
_greeters =  nearestObjects [vehicle player, ["MAN"], 50];

sleep1;

while {true} do
 {
      {
        if (_x distance vehicle player < 5 AND side _x == west) then
        {
            hint "hello";
            sleep 1;
        };
      } forEach _greeters;
sleep 1;
 };


But in a trigger this doesn't work:
Code: [Select]
Condition: {_x distance player < 5} forEach greeters
onActivation: hint "hello"

Variable greeters initialized of course  :P

In fact the editor doesn't even accept the condition code  >:(

Weird   ???

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

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Limited code in triggers ?
« Reply #1 on: 10 May 2009, 17:44:08 »
The former case definitely should work. Any problems with it are due to logical rather than syntactic errors (that is, it is acting as it should, but you are expecting it to act differently).

The issue with the latter case is that forEach always returns nil, so it isn't appropriate to be used directly in a condition. Instead, try:
Code: (Condition) [Select]
({_x distance player < 5} count (nearestObjects [vehicle player, ["MAN"], 50])) > 0
What this does is count how many men are close to the player, and the condition is true if one or more of them are. However, it is a lot simpler once you get more complex scripts, just to run them in files, not in triggers themselves, since they are designed for simple functionality.

Your script is also different to the action of a trigger, since it will say "hello" once for each person near the player and once every second in this case. A trigger version would say "hello" when someone approached, but not say it again until the player was on his own again and then someone new approached.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: Limited code in triggers ?
« Reply #2 on: 10 May 2009, 19:16:12 »
Thanks a lot again Spooner  :good:

Had no idea that nil was returned if in a trigger, wish they'd tell you  :whistle:

Quote
The former case definitely should work
Should yes, but I'm pretty sure it doesn't and I have had this editing problem since OFP, causing a need for additional triggers. My logic can't be THAT bad or... Will return after more extensive testing  :scratch:

Laggy
« Last Edit: 10 May 2009, 19:22:14 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 Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Limited code in triggers ?
« Reply #3 on: 11 May 2009, 03:40:47 »
Well, anything that doesn't specifically return something returns nil. Mostly that isn't an issue, since the value is ignored when just one of the statements in a script. Unfortunatly, SQF does not follow accepted conventions of what does and what does not return a value, which doesn't help you even if you are experienced in such things elsewhere ;) Just something you have to learn...

Yes, I think you need to give an actual example of where that and/or statement wasn't working. I still think you are mistaken, but...
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)