Jump to content
Sign in to follow this  
OneStiffRod

2d arrays?

Recommended Posts

Firstly tell me the proper way to create an array - the script reference does a terrible job at actually showing syntax.

is it:

_myarray [0,0,0,0,0] like this?

or

_myarray = Array(10) can I do it like this?

2ndly, I need to have psuedo objects like classes in C++, I can do this with a 2D array but not sure if OFP will recognize.

Share this post


Link to post
Share on other sites
Guest

Proper syntax:

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">_myArray = [1,2,3,4]

<span id='postcolor'>

2D arrays (matrices)

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_myArray = [ [1,2] , [3,4] ]

<span id='postcolor'>

To access the elements of the matrix, use

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_element = (_myArray select _row) select _column

<span id='postcolor'>

The arrays can contain any type of objects and you can mix them as you wish.

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_myArray = [ [1,"Hello"],["world",2.3456] ]

Hint format ["%1 %2", (_myArray select 0) select 1, (_myArray select 1) select 0]

<span id='postcolor'>

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×