OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Mock360 on 13 Aug 2006, 05:10:46
-
Is there a command or script to "MoveInCargo" an entire named group? I have looked here, in other forums, and in a few scripting guides. Can't seem to find it.
Oh yeh - I'm a n00b at this scripting thing!
-
Put this in the init field of one of the units of the group:
{_x moveInCargo vehiclename} forEach units group this
If you want to do the same thing in a script after the start of the mission put this line in your script
{_x moveInCargo vehiclename} forEach units nameofgroup
To give a group a name put this in the init field of one of the units in the group:
nameofgroup = group this
-
Thank you for your response. It worked great.
Could you briefly explain or could you point me toward an explanation of the use of "{ }" brackets as opposed to "[ ]" brackets within the init line? When I inadvertantly used [_x moveInCargo vehiclename] instead of {_x moveInCargo vehiclename}, I got an error message that said I was trying to use a global variable in local environment.
-
( ) [ ] and { } are profoundly different in OFP scripting.
( ) is used to make things happen in the right order. For example (2+3)/4 is different from 2+(3/4)
[ ] is used to indicate taht the contents of the brackets constitute an array
{ } is used to indicate that the contents of the brackets is a string. Sometimes you can use " " instead.
There are subtleties, which no doubt somebody will explain, but that's the basics of it.
-
I am with mac up to the {} bit.
Think of "" as defining a string: "this is a string"
and {} as defining a block of code: {a=5;c=7;b=a+c}
They can sometimes be used interchangably - but sometimes not hence it is best to be clear on the distinction between a string and a block of code.
What I think was also implied by your question is how does the forEach command work. It works like this:
{block of code using _x} forEach array
It will run the block of code once for every element of the array where each element replaces the _x. So;
{_x setPos getPos player;[_x] join player} forEach [unit1,unit2,unit3]
will move each of the units to the location of the player and get them to join him. It is exactly like:
unit1 setPos getPos player
[unit1] join player
unit2 setPos getPos player
[unit2] join player
unit3 setPos getPos player
[unit3] join player
Except it is neater and easier to read, and also less error prone.
-
Thanks for the information. I think it is going to help with a VBIED (vehicle borne IED) script I have been experimenting with.