Home   Help Search Login Register  

Author Topic: HELP!!! I need an FAQ explaining the use of "ARRAYS"  (Read 2017 times)

0 Members and 1 Guest are viewing this topic.

tai mai shu

  • Guest
if anyone could post a link or a post relating to arrays?  itsd be GREATLY appreciated.

Tactician

  • Guest
Re:HELP!!! I need an FAQ explaining the use of "ARRAYS"
« Reply #1 on: 25 Aug 2002, 17:00:14 »
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.

tai mai shu

  • Guest
Re:HELP!!! I need an FAQ explaining the use of "ARRAYS"
« Reply #2 on: 25 Aug 2002, 23:17:24 »
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!

Tactician

  • Guest
Re:HELP!!! I need an FAQ explaining the use of "ARRAYS"
« Reply #3 on: 27 Aug 2002, 12:40:04 »
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.

tai mai shu

  • Guest
Re:HELP!!! I need an FAQ explaining the use of "ARRAYS"
« Reply #4 on: 27 Aug 2002, 22:50:29 »
C++ really helps??? ok if it does, first thing today, im gonna go buy "C++ for dummies" lol.  thanks man.