| 01-20-2010, 02:29 AM | #1 |
JASS:library test struct dummy integer array 2d [1][1] endstruct endlibrary line XXX: Unexpected: "[1]" Any way to cheat the system for a 2d array inside a struct, without using a method/math inside the []? |
| 01-20-2010, 03:21 AM | #2 |
Table array? |
| 01-20-2010, 04:05 AM | #3 |
manually manage the 2D array. |
| 01-20-2010, 05:39 AM | #4 |
library test struct dummy[8190 integer array x2d[64] endstruct endlibrary |
| 01-20-2010, 05:46 AM | #5 | ||
Quote:
I was afraid of that... Quote:
hmm, that is interesting..., but still requires me to do some rough work. I think the easiest way is to use a regular array in the struct--with either a constant method (possible?) or in-line my math commands--and just live with it. Thanks guys. |
| 01-20-2010, 06:15 AM | #6 |
check pools script it uses 256 size sub arrays. |
| 01-20-2010, 09:04 AM | #7 |
We used to simulate 2D arrays with dynamic arrays: basically by having an array of arrays. |
| 01-20-2010, 12:41 PM | #8 |
easy: JASS:globals constant integer ARRAY_SIZE_X=<> constant integer ARRAY_SIZE_Y=<> constant integer ARRAY_SIZE=ARRAY_SIZE_X*ARRAY_SIZE_Y endglobals struct bääää integer array arr[ARRAY_SIZE] method getArrayData takes integer x, integer y returns integer if x>=ARRAY_SIZE_X or y>=ARRAY_SIZE_Y then //that no 1 accesses invalid indices return 0 endif return .arr[y*ARRAY_SIZE_Y+x] endmethod method setArrayData takes integer x, integer y, integer data returns nothing if x>=ARRAY_SIZE_X or y>=ARRAY_SIZE_Y then //that no 1 accesses invalid indices return endif set .arr[y*ARRAY_SIZE_Y+x]=data endmethod endstruct |
| 01-20-2010, 08:41 PM | #9 |
That does not give you the nice 2D array syntax though. JASS:type innerarray extends integer array[ARRAY_SIZE_Y] struct foo innerarray array bar[ARRAY_SIZE_X] static method create takes nothing returns foo local foo this=foo.allocate() local integer i=0 loop exitwhen i>=ARRAY_SIZE_X set .bar[i]=innerarray.create() set i=i+1 endloop return this endmethod method onDestroy takes nothing returns nothing local integer i=0 loop exitwhen i>=ARRAY_SIZE_X call bar[i].destroy() set i=i+1 endloop endmethod endstruct local foo f=foo.create() set f.bar[1][3]=1 |
| 01-20-2010, 08:57 PM | #10 | |
Quote:
if jh has "real" operators (no blame for vex), you can simulate real arrays, but without... |
| 01-20-2010, 10:10 PM | #11 | |
Quote:
That's pretty neat. Thanks. |
| 01-20-2010, 11:21 PM | #12 |
With enough hacking and a text macro I think you can have tot's solution AND [][] syntax. I'll leave it as an exercise. |
| 01-21-2010, 06:13 PM | #13 | |
Quote:
??? [][] operators...in vJass??? have i missed something?? |
| 01-21-2010, 07:52 PM | #14 |
The trick is to be creative. |
| 01-21-2010, 08:42 PM | #15 |
In all honesty, I am not sure how the textmacro would help in allowing [][] syntax. Truthfully, I have used text-macros once, and only for readability (cause I could have copied and pasted the code and changed what I wanted faster than I learnt how to use them). with structs you can overload [], so I'm guessing thats one of the operations. Arrays are the only other object that use []... I'm just thinking here... |
