Home   Help Search Login Register  

Author Topic: Addaction and foreach  (Read 667 times)

0 Members and 1 Guest are viewing this topic.

klavan

  • Guest
Addaction and foreach
« on: 16 Jul 2005, 11:34:08 »
I want to add an action to every unit that are part of a certain array, so i create this line:

{_X addaction [localize "STRM_act1","Common\attack1.sqs"]} foreach east_units

The problem: the action doesn't appear.

The array is crated via trigger that cover the entire map using thislist for add every east units in the east_units array.
I don't receive any error message, simply the action doesn't appear.
I've attepted adding "list" and "units" command after the foreach, but nothing.
This line is called in the init file of the mission.
Any help?
Thanks.
Klavan


Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Addaction and foreach
« Reply #1 on: 16 Jul 2005, 11:46:44 »
Try:

{_X addaction [{localize "STRM_act1"},{Common\attack1.sqs}]} foreach east_units


also I suggest you do a  

hint format ["%1",east_units]

to check that the array contains what you expect.

Note that creating the array the way you do you will have vehicles as units and so will add the action to them, but not to the loons within the vehicles.
« Last Edit: 16 Jul 2005, 11:48:51 by THobson »

klavan

  • Guest
Re:Addaction and foreach
« Reply #2 on: 16 Jul 2005, 11:55:40 »

Note that creating the array the way you do you will have vehicles as units and so will add the action to them, but not to the loons within the vehicles.


Thanks for the help. I'm going to try it now. And many thanks for the note above, since it's suppossed you cannot kill a tank with your rifle's buttstock!!!
 ;D
Thanks
Klavan
« Last Edit: 16 Jul 2005, 12:03:56 by klavan »

klavan

  • Guest
Re:Addaction and foreach
« Reply #3 on: 16 Jul 2005, 12:06:10 »
 :-\
Nothing happened, with your suggested line, but i receive  a  "scalar bool array string xyyteycvsdetc."  message with the hint.
Whet the hell this means?
Thanks.
Klavan
« Last Edit: 16 Jul 2005, 12:20:45 by klavan »

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Addaction and foreach
« Reply #4 on: 16 Jul 2005, 12:26:07 »
It means your array is undefined.  In other words whatever you are doing to create the array is not working.

Look at Reply #1 here for how to do that;
http://www.ofpec.com/yabbse/index.php?board=6;action=display;threadid=24666
« Last Edit: 16 Jul 2005, 12:27:42 by THobson »

klavan

  • Guest
Re:Addaction and foreach
« Reply #5 on: 16 Jul 2005, 12:36:59 »
OK, i've took a look at it and it's clear, but does this mean that's  the only way to create such an array?
This is  the way I did to create it:

Make a trigger, covering the entire mission area
Activation = "once" and "east present"
In the "on activation" field: "east_units = thisList"

This should work....or not?
Thanks
klavan
« Last Edit: 16 Jul 2005, 12:37:48 by klavan »

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Addaction and foreach
« Reply #6 on: 16 Jul 2005, 12:51:48 »
Well that should work - but you will have the problem of the list ignorinmg unit in vehicles.

It could be that you are running your code before the array has been created.  Put a delay in the script of a few seconds.

klavan

  • Guest
Re:Addaction and foreach
« Reply #7 on: 16 Jul 2005, 13:06:37 »
Well that should work - but you will have the problem of the list ignorinmg unit in vehicles.

It could be that you are running your code before the array has been created.  Put a delay in the script of a few seconds.

It's a thought I've done many times before now: what does OFP reads before? The init file or the commands presents in the init fields of the units or in the activation fields of the triggers?
However, i'm leaving for a (very) short vacation (36 hours). So my thoughts are wondering toward other places, for the moment.  ;)
Byebye
Thanks for your help.
Klavan

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Addaction and foreach
« Reply #8 on: 16 Jul 2005, 21:45:32 »
Try using a lowercase "x" instead of an uppercase one. I'm pretty sure OFP is case-sensitive about this kind of stuff, and I've always used lowercase:

{_x addaction [localize "STRM_act1","Common\attack1.sqs"]} foreach east_units
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

klavan

  • Guest
Re:Addaction and foreach
« Reply #9 on: 17 Jul 2005, 20:48:43 »
I've solved the problem.
I had put the line directly in the "On Activation" field of the same  trigger that generates the array. Now the action appears and the script runs OK.
It seems just like OFP reads the init file before and then the stuffs in the map, thus ignoring, in this case,  the creation of the array.
I wonder if this might compromise the running of other scripts   which could run using similar commands.....
Thanks.
Klavan

   
« Last Edit: 17 Jul 2005, 23:54:09 by klavan »