| 12-11-2009, 09:47 PM | #1 |
passing an array errors out. Is it possible to do? If so, how could I pass an array without setting it first like in other scripting languages? Array(0, 1, 2, 3) JASS:function testArrays takes integer array items returns nothing endfunction |
| 12-11-2009, 09:56 PM | #2 |
No. It is not possible. Pass a struct that contains the array. |
| 12-11-2009, 10:20 PM | #3 |
JASS:type MyArray extends integer array[100] //100 is the size, 99 is max index per instance function Test takes MyArray ma returns nothing call BJDebugMsg(I2S(ma[0])) //prints 1 call BJDebugMsg(I2S(ma[99])) //prints 777 endfunction function Example takes nothing returns nothing local MyArray ma = MyArray.create() set ma[0] = 1 set ma[99] = 777 call Test(ma) endfunction The above shows how to use a basic dynamic array. Your other options are to use an array member of a struct and pass the struct, or to use method operators to make the struct itself behave as an instantiatable array: JASS:struct MyArray private real array data[100] method operator [] takes integer i returns real return data[i] endmethod method operator []= takes integer i, real r returns nothing set data[i] = r endmethod endstruct Now you can use this MyArray struct in an identical way to the first example, and even add your own stuff such as a .size member if you wanted to. |
| 12-12-2009, 12:44 AM | #4 |
Don't forget to .destroy() it when you're done with it. |
