![]() |
#1 |
I blink, therefore I am.
Join Date: Sep 2006
Posts: 1,812
![]() ![]() ![]() ![]() |
![]() ![]() 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 []? |
![]() |
![]() |
Sponsored Links - Login to hide this ad! |
|
![]() |
#2 |
default string
|
![]() Table array?
|
![]() |
![]() |
![]() |
#3 |
User
Join Date: Jan 2007
Posts: 542
![]() ![]() ![]() |
![]() manually manage the 2D array.
__________________ |
![]() |
![]() |
![]() |
#4 |
obey
|
![]() library test
struct dummy[8190 integer array x2d[64] endstruct endlibrary |
![]() |
![]() |
![]() |
#5 | ||
I blink, therefore I am.
Join Date: Sep 2006
Posts: 1,812
![]() ![]() ![]() ![]() |
![]() 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. |
||
![]() |
![]() |
![]() |
#6 |
obey
|
![]() check pools script it uses 256 size sub arrays.
|
![]() |
![]() |
![]() |
#7 |
Procrastination Incarnate
Development Director
|
![]() We used to simulate 2D arrays with dynamic arrays: basically by having an array of arrays.
__________________ |
![]() |
![]() |
![]() |
#8 |
†6†
Join Date: Oct 2008
Posts: 841
![]() ![]() |
![]() easy:
__________________![]() 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 Last edited by Tot : 01-20-2010 at 01:48 PM. |
![]() |
![]() |
![]() |
#9 |
Procrastination Incarnate
Development Director
|
![]() That does not give you the nice 2D array syntax though.
__________________![]() 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 |
![]() |
![]() |
![]() |
#10 | |
†6†
Join Date: Oct 2008
Posts: 841
![]() ![]() |
![]() Quote:
if jh has "real" operators (no blame for vex), you can simulate real arrays, but without... Last edited by Tot : 01-20-2010 at 10:00 PM. |
|
![]() |
![]() |
![]() |
#11 | |
I blink, therefore I am.
Join Date: Sep 2006
Posts: 1,812
![]() ![]() ![]() ![]() |
![]() Quote:
That's pretty neat. Thanks. |
|
![]() |
![]() |
![]() |
#12 |
Free Software Terrorist
Technical Director
|
![]() With enough hacking and a text macro I think you can have tot's solution AND [][] syntax. I'll leave it as an exercise.
__________________ |
![]() |
![]() |
![]() |
#13 | |
†6†
Join Date: Oct 2008
Posts: 841
![]() ![]() |
![]() Quote:
??? [][] operators...in vJass??? have i missed something?? |
|
![]() |
![]() |
![]() |
#14 |
Free Software Terrorist
Technical Director
|
![]() The trick is to be creative.
__________________ |
![]() |
![]() |
![]() |
#15 |
I blink, therefore I am.
Join Date: Sep 2006
Posts: 1,812
![]() ![]() ![]() ![]() |
![]() 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... Last edited by Ammorth : 01-21-2010 at 09:42 PM. |
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
|
|