Home   Help Search Login Register  

Author Topic: Iterative triggers?  (Read 1596 times)

0 Members and 1 Guest are viewing this topic.

Offline Trexian

  • Members
  • *
Iterative triggers?
« on: 24 Sep 2008, 15:11:08 »
(This *may* belong in the advanced, but I was in doubt.) :)

Here is my situation.

I generate a list of cities in an array.  I then randomly select some of the cities for a trigger, generating another array.

I then want to do a loop - currently a for [{_i = 0}, {_i <= _count}, {_i = _i + 1}] do type loop - and create a marker and a trigger for each city.  I can get the marker to work, using a command that formats a variable "_text" with a string that incorporates the identity of the city.  If I "manually" designate which city (like element 0), it will properly create a trigger for that city.  But, if I use the iterator _i as the element of the city array to select, I get all sorts of errors - oddly, with the iterator command, not with the trigger, though.

Here is the code that doesn't work for the trigger.

Code: [Select]
//set trigger
_spawnTrig = createTrigger ["EmptyDetector", _posCenter];
sleep .5;
_spawnTrig setTriggerArea [_radiusA, _radiusB, 0, false];
_spawnTrig setTriggerActivation ["ANY", "present", true];
_spawnTrig setTriggerStatements ["this","[] execVM ""helloworld.sqf""",""];

I *suspect* that the problem is using the same variable _spawnTrig for each trigger in the iteration.  But, that means resorting to a format command for the variable.  I tried that.  And failed miserably.

I believe all the variables are properly scoped, because I use the same variables  (_posCenter, _radiusA, _radiusB) to set the markers in the same loop, and the markers appear to be set correctly.

TIA.
T

Edit.
Oops.  First time ever.  Found the answer (I think) at the BI Forums instead of here. :)

http://www.flashpoint1985.com/cgi-bin/ikonboard311/ikonboard.cgi?s=93a2848e5269814e62e9b2e824e359a9;act=ST;f=71;t=73975;hl=dynamic+and+trigger

Will post the solution if/when I get it. :)  :good:
« Last Edit: 24 Sep 2008, 16:35:39 by Trexian »
Sic semper tyrannosauro.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Iterative triggers?
« Reply #1 on: 24 Sep 2008, 17:24:08 »
I think you need to use "nul = [] execVM ""helloworld.sqf""" in the trigger, as you would if putting it in the editor.

Quote
I *suspect* that the problem is using the same variable _spawnTrig for each trigger in the iteration.  But, that means resorting to a format command for the variable.  I tried that.  And failed miserably.
Well, on one side there isn't a problem with reusing the _spawnTrig variable. On the other, 99% of people who use dynamic code generation (call compile format) should have just used an array or some other method instead (the link shows someone who didn't need dynamic code at all).

I can't really say more than that if you don't share your errors and/or more of the code. The errors could be absolutely anywhere...
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Trexian

  • Members
  • *
Re: Iterative triggers?
« Reply #2 on: 24 Sep 2008, 18:01:18 »
Hey-

Could you elaborate more on the idea of not needing to do this dynamically? :)  What could that other guy have used instead?

 :clap:
Sic semper tyrannosauro.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Iterative triggers?
« Reply #3 on: 24 Sep 2008, 19:11:29 »
OK, there still needs to be a tiny bit of dynamic code in my solution! Still, there's absolutely no dynamic variables, so I hope you forgive me...

Code: (set up 3 triggers) [Select]
triggers = []; // List of triggers that we will make.
_tPosX = (getPos player) select 0;
_tSize = 20;

for "_i" from 0 to 2 do
{
_tPosY = ((getPos player) select 1) + 50 * _i;

_trigger = createTrigger ["EmptyDetector", [_tPosX, _tPosY]];
_trigger setTriggerArea [_tSize, _tSize, 0, true];
_trigger setTriggerActivation ["WEST", "PRESENT", true];
_trigger setTriggerStatements ["this", format ["nul = [%1] execVM 'trigger.sqf'", _i], ""];

triggers = triggers + [_trigger]; // Store this trigger into the list.
};

Code: (trigger.sqf) [Select]
_triggerIndex = _this select 0;

_trigger = triggers select _triggerIndex; // Take the trigger out of the list again.

// do stuff with the trigger...

Frankly, though, I imagine all you and he wanted to do was have access to the objects that triggered the trigger (thisList , when used within the code in a trigger, is the same as "list _trigger" used in a script), in which case, it could have just been:
Code: [Select]
        _trigger setTriggerStatements ["this", "nul = thisList execVM 'trigger.sqf'", ""];
« Last Edit: 24 Sep 2008, 19:13:04 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Trexian

  • Members
  • *
Re: Iterative triggers?
« Reply #4 on: 24 Sep 2008, 19:53:27 »
Can I cuss?  I mean, if not, I'll just say:
DAAAAAAAAAAAAAAAANG that's slick.   :clap:

I'll have to work through that, but I *may* need to pass some more variables to the activated script, like the center location and radii of the trigger.  BUT, I think I can see where that goes in what you propose....

My specific need is to set triggers in random cities that are triggered when the player enters the trigger area.  So, the "player in thislist" will play a role eventually, but I've done that before.

Putting the triggers in a global array helps make sure the game isn't confused by reassigning the same local variable to a new trigger?  Yeah, it is probably more complicated than that, but that's how my brain can analyze it.

Great food for thought.

Edit:

Spooner, you ROCK! :D

Tried your way first (naturally) ;) and it did the trick with my test script.  But, when I tried to enter different parameters, it didn't like them.  Local variable in global space or somesuch.  But, re-reading:
Code: [Select]
_triggerIndex = _this select 0;

_trigger = triggers select _triggerIndex; // Take the trigger out of the list again.
And it clicked.

The variables I need the position, and the radii, I can use the same technique you used for the triggers and use a global array.  Then, I only need to keep track of _i as the index, and grab the stuff I need from there.

Of course, in looking at it again this morning (amazing what clarity a decent night sleep can bring), I think I see what I was doing wrong, but I still think I like the global array solution better.
« Last Edit: 25 Sep 2008, 14:34:15 by Trexian »
Sic semper tyrannosauro.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Iterative triggers?
« Reply #5 on: 25 Sep 2008, 17:44:51 »
You don't strictly need to use arrays to store the other information, because it is either already available from the trigger itself or can be stored inside the code string (we only need to pass the trigger itself via an array because it can't be serialised into a string):
Code: [Select]
_trigger setTriggerStatements ["this", format ["nul = [%1, %2] execVM 'trigger.sqf'", _i, _tSize], ""];

Code: [Select]
_triggerIndex = _this select 0;
_triggerRadius = _this select 1;

_trigger = triggers select _triggerIndex;
_triggerPos = getPos _trigger;
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Trexian

  • Members
  • *
Re: Iterative triggers?
« Reply #6 on: 25 Sep 2008, 19:50:53 »
For markers, there are the getMarker* commands.  But, I don't see anything similar for triggers? :scratch:

(And continuing thanks... again.)
Sic semper tyrannosauro.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Iterative triggers?
« Reply #7 on: 25 Sep 2008, 20:21:14 »
There aren't. All you can do with it are the setTrigger* commands, getPos and setPos (when I said "already available from the trigger itself", I meant just the position). The radius I had to send through in the function parameters because you can't ask the trigger for this information.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)