Home   Help Search Login Register  

Author Topic: ForEach problem  (Read 1101 times)

0 Members and 1 Guest are viewing this topic.

GeneralCoder

  • Guest
ForEach problem
« on: 15 Nov 2002, 20:44:10 »
Hi i encountered a problem when i was trying to use foreach operator

u see if i have car named car1
i can do this:
"_x AssignAsCargo car"  ForEach _units

But! if i get the car like this (argument from exec)
cars initialazation line:
this exec"my_script.sqs"

car1 = _this
then the "_x AssignAsCargo car1"  ForEach _units
doesnt work

what do do? :-\

« Last Edit: 15 Nov 2002, 20:45:46 by GeneralCoder »

Offline toadlife

  • OFPEC Old Skool
  • Former Staff
  • ****
  • Official OFP Editing Center Toad
    • toadlife.net
Re:ForEach problem
« Reply #1 on: 15 Nov 2002, 21:25:19 »
Does the script know what "_units" is?

Perhaps you need to declare what _units means in the script like so...

car1 = _this
_units = units mygroup
"_x AssignAsCargo car1"  ForEach _units

BTW, I dont think you need to delare what _this is...just make it  like this...

_units = units mygroup
"_x AssignAsCargo _this"  ForEach _units





EDIT

Orr.... you could initialize the script like this:

[car,group] exec "myscript.sqs"

And have the script look like this:

_car = _this select 0
_units = units (_this select 1)
"_x AssignAsCargo _car"  ForEach _units

« Last Edit: 15 Nov 2002, 21:29:01 by toadlife »
"Whenever you want information on the 'net, don't ask a question; just post a wrong answer." -- Cancer Omega.

GeneralCoder

  • Guest
Re:ForEach problem
« Reply #2 on: 15 Nov 2002, 23:42:14 »
Does the script know what "_units" is?

Perhaps you need to declare what _units means in the script like so...

car1 = _this
_units = units mygroup
"_x AssignAsCargo car1"  ForEach _units

BTW, I dont think you need to delare what _this is...just make it  like this...

_units = units mygroup
"_x AssignAsCargo _this"  ForEach _units





EDIT

Orr.... you could initialize the script like this:

[car,group] exec "myscript.sqs"

And have the script look like this:

_car = _this select 0
_units = units (_this select 1)
"_x AssignAsCargo _car"  ForEach _units



hmmmmm....

this is what i got in my script and i dont get error it just doesnt do anything:

mans initialazation line:
[this,car1] exec"myscript.sqs"

_man = _this select 0
_veh = _this select 1
_units = units group _man

"_x AssignAsCargo _veh"  ForEach _units

but like i sayd this would work:
"_x AssignAsCargo car1"  ForEach _units

 ???


Offline toadlife

  • OFPEC Old Skool
  • Former Staff
  • ****
  • Official OFP Editing Center Toad
    • toadlife.net
Re:ForEach problem
« Reply #3 on: 16 Nov 2002, 03:30:46 »
assignascargo wont do anything except assign the units as cargo. Have you tried ordering them to get in?

_man = _this select 0
_veh = _this select 1
_units = units group _man

"_x AssignAsCargo _veh"  ForEach _units
_units ordergetin true

Also, if the player is the leader of the group, none of these commands will do a damn thing anyway!
"Whenever you want information on the 'net, don't ask a question; just post a wrong answer." -- Cancer Omega.

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:ForEach problem
« Reply #4 on: 16 Nov 2002, 11:26:47 »
u got somthin rong there Toad - he cant do

"_x AssignAsCargo _car"  ForEach _units

da foreach command can get only 1 private (is dat how its called ?) vari

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

GeneralCoder

  • Guest
Re:ForEach problem
« Reply #5 on: 16 Nov 2002, 12:47:54 »
assignascargo wont do anything except assign the units as cargo. Have you tried ordering them to get in?

_man = _this select 0
_veh = _this select 1
_units = units group _man

"_x AssignAsCargo _veh"  ForEach _units
_units ordergetin true

Also, if the player is the leader of the group, none of these commands will do a damn thing anyway!

Oh sure i order them to get in later but belive me now the problem is that foreach line becose if theres line

"_x AssignAsCargo vehicle_name"
not parameter _car

everything works, so it just doesnt seem to work as parameter.    :(
« Last Edit: 16 Nov 2002, 12:55:20 by GeneralCoder »

GeneralCoder

  • Guest
Re:ForEach problem
« Reply #6 on: 16 Nov 2002, 12:52:50 »
u got somthin rong there Toad - he cant do

"_x AssignAsCargo _car"  ForEach _units

da foreach command can get only 1 private (is dat how its called ?) vari

LCD OUT

What do u mean?

i have repeat my self again and say:

doesnt work!
"_x AssignAsCargo _car"  ForEach _units

works!
"_x AssignAsCargo name_of_the_vehicle"  ForEach _units

and i know that _car is correct variable becose i have some other code parts like
man AssignAsDriver _car
and that works!
 :-\

GeneralCoder

  • Guest
Re:ForEach problem
« Reply #7 on: 16 Nov 2002, 12:57:33 »
Heres the code what should but soldiers in the vehicle:

_man = _this select 0
_veh = _this select 1
_units = units group _man
_group = group _man

"_x AssignAsCargo _veh"  ForEach _units
(leader _group) AssignAsDriver _veh

_units OrderGetIn true

leader goes in but soldiers doesnt, maybe u should try this and see can u get it work?

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:ForEach problem
« Reply #8 on: 16 Nov 2002, 13:22:57 »
strange didnt work 4 me  :( nywayz here is anoder Q can u use 2 foreaches ?

like

Code: [Select]
"[_x] exec _script" foreach [soldiera,soldierb] forach [scripta,scriptb]
im sure it wil not b writed like dat but i wanna know  ;)

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline toadlife

  • OFPEC Old Skool
  • Former Staff
  • ****
  • Official OFP Editing Center Toad
    • toadlife.net
Re:ForEach problem
« Reply #9 on: 16 Nov 2002, 23:35:24 »
Code: [Select]
_man = _this select 0
_veh = _this select 1
_units = units group _man

"_x AssignAsCargo _veh"  ForEach _units
_units ordergetin true

Dunno what the problem is. I just tested the above code and it works fine. They all jump in the URAL.

Alternatetly, the code below makes them all jmp in as cargo, except for one of them, who jumps in the drvier's seat.

Code: [Select]
_man = _this select 0
_veh = _this select 1
_units = units group _man

"_x AssignAsCargo _veh"  ForEach (_units - [_units select 1])
_units select 1 AssignAsDriver _veh
_units OrderGetIn true


I have  a feeling your making a typo somewhere.
"Whenever you want information on the 'net, don't ask a question; just post a wrong answer." -- Cancer Omega.

Offline toadlife

  • OFPEC Old Skool
  • Former Staff
  • ****
  • Official OFP Editing Center Toad
    • toadlife.net
Re:ForEach problem
« Reply #10 on: 16 Nov 2002, 23:39:10 »


Code: [Select]
"[_x] exec _script" foreach [soldiera,soldierb] forach [scripta,scriptb]

I think you can nest foreach statements, but the code would look like this...

Code: [Select]
"""[_x] exec _script"" foreach [soldiera,soldierb]" foreach [scripta,scriptb]

Someone here know that proper sytax for nesting foreach statements. I'm no programmer, so maybe someone can pipe in and set us straight.
"Whenever you want information on the 'net, don't ask a question; just post a wrong answer." -- Cancer Omega.

Offline Dinger

  • Contributing Member
  • **
  • where's the ultra-theoretical mega-scripting forum
Re:ForEach problem
« Reply #11 on: 17 Nov 2002, 21:58:48 »

"""[_x] exec _script"" foreach [soldiera,soldierb]" foreach [scripta,scriptb]
 
close toadlife

First, with 1.85, the Gods of OFP have given us curly brackets {} to take the role of quotes, allowing us nesting without double quotes (which only give us one level of nesting anyway).
Second, in any foreach, _x represents the element in the array.

So, you want:
Code: [Select]
{_temp = _x; {[_x] exec _temp} ForEach [SoldierA, soldierB]} ForEach [scripta, scriptb]
Dinger/Cfit

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:ForEach problem
« Reply #12 on: 17 Nov 2002, 22:11:37 »
tank u dinger  :-*

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline toadlife

  • OFPEC Old Skool
  • Former Staff
  • ****
  • Official OFP Editing Center Toad
    • toadlife.net
Re:ForEach problem
« Reply #13 on: 18 Nov 2002, 03:31:33 »
Neato. I just might use that someday. I really need to teach myself some real programming languages.
« Last Edit: 18 Nov 2002, 03:33:18 by toadlife »
"Whenever you want information on the 'net, don't ask a question; just post a wrong answer." -- Cancer Omega.