OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting Multiplayer => Topic started by: tai mai shu on 25 Aug 2002, 03:36:57
-
if anyone could post a link or a post relating to arrays? itsd be GREATLY appreciated.
-
So you haven't taken Algebra 1 yet? ;D
An array, when you visualize it, is a field of numbers within brackets seperated by commas.
[1,4,2,435897,-8.4]
To set an array, use something like this.
myArray = [1,4,2,435897,-8.4]
Now you can tell OFP to look at a certain element of the array. The first element is always "0".
myNumber = myArray select 0
myNumber is now equal to 1.
myNumber = myArray select 3
myNumber is now equal to -8.4.
You can add elements to arrays like this.
myArray = myArray + [23]
myArray is now equal to [1,4,2,435897,-8.4,23]
You can remove a certain element like this.
myArray = myArray - [4]
myArray is now equal to [1,2,435897,-8.4,23]
With some more creativity, you can remove a certain element of the array.
myArray = myArray - [myArray select 2]
myArray is now equal to [1,2,-8.4,23]
You can also check to see if a certain number is in the array.
?(23 in myArray): hint "true"
true
?(56 in myArray): hint "true"
...
Now, the really trippy part is that objects work in arrays too.
newArray = [flag1, flag2]
A useful command with object arrays is forEach. The command in commas is executed for each element or the array, with _x being the object.
"_x setFlagSide WEST" forEach newArray
If you've set some of your units to a group, you can use the units in it as an array. This would heal all members of the player's group.
"_x setdammage 0" forEach units (group player)
Hope it made some sense. Good luck.
-
thanks m8! that helps me out a lot. i mean, i know about arrays in mathematics (im 14 and taking calculus ;D) but i didnt know how to utilize them in ofp, seeing how they are pretty much just as important and versatile as scripting itself.
ive pretty much got these arrays nailed. thanks!
-
Learning another programming language like C++ really boosts your awareness of OFPScript.
Heh.. I'm 18 and haven't even seen a calculus expression I can recognize.
-
C++ really helps??? ok if it does, first thing today, im gonna go buy "C++ for dummies" lol. thanks man.