wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Warcraft III Modding > Developer's Corner > Triggers & Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 01-20-2010, 03:29 AM   #1
Ammorth
I blink, therefore I am.
 
Ammorth's Avatar
 
Join Date: Sep 2006
Posts: 1,812

Submissions (10)

Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)

Default 2D array in struct?

Collapse 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 []?
__________________
Ammorth is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 01-20-2010, 04:21 AM   #2
Fledermaus
default string
 
Fledermaus's Avatar
 
Join Date: May 2006
Posts: 705

Submissions (1)

Fledermaus is a jewel in the rough (194)Fledermaus is a jewel in the rough (194)Fledermaus is a jewel in the rough (194)

Send a message via MSN to Fledermaus
Default

Table array?
Fledermaus is offline   Reply With Quote
Old 01-20-2010, 05:05 AM   #3
Deaod
User
 
Join Date: Jan 2007
Posts: 542

Submissions (11)

Deaod is a jewel in the rough (192)Deaod is a jewel in the rough (192)Deaod is a jewel in the rough (192)

Default

manually manage the 2D array.
__________________
Deaod is offline   Reply With Quote
Old 01-20-2010, 06:39 AM   #4
DioD
obey
 
DioD's Avatar
 
Join Date: Feb 2006
Posts: 1,532

Submissions (4)

DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)

Send a message via ICQ to DioD
Default

library test
struct dummy[8190
integer array x2d[64]
endstruct
endlibrary
DioD is offline   Reply With Quote
Old 01-20-2010, 06:46 AM   #5
Ammorth
I blink, therefore I am.
 
Ammorth's Avatar
 
Join Date: Sep 2006
Posts: 1,812

Submissions (10)

Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)

Default

Quote:
Originally Posted by Deaod
manually manage the 2D array.

I was afraid of that...

Quote:
Originally Posted by DioD
Collapse JASS:
library test
    struct dummy[8190]
        integer array x2d[64]
    endstruct
endlibrary

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.
__________________
Ammorth is offline   Reply With Quote
Old 01-20-2010, 07:15 AM   #6
DioD
obey
 
DioD's Avatar
 
Join Date: Feb 2006
Posts: 1,532

Submissions (4)

DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)

Send a message via ICQ to DioD
Default

check pools script it uses 256 size sub arrays.
DioD is offline   Reply With Quote
Old 01-20-2010, 10:04 AM   #7
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

We used to simulate 2D arrays with dynamic arrays: basically by having an array of arrays.
__________________
Anitarf is offline   Reply With Quote
Old 01-20-2010, 01:41 PM   #8
Tot
†6†
 
Tot's Avatar
 
Join Date: Oct 2008
Posts: 841

Tot will become famous soon enough (53)Tot will become famous soon enough (53)

Default

easy:
Collapse 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
__________________
Current Projects:
  • Masters Of WarCraft: Some mixture of AoS and RPG
    Terrain: 100%, Coding: 75%, Heroes: 0%, Items: 0%, Creeps: 0%, Upgrades: 0%
  • hunting emos
____________________________________
scheiss kack dreck sausacksau bundeswehr

Last edited by Tot : 01-20-2010 at 01:48 PM.
Tot is offline   Reply With Quote
Old 01-20-2010, 09:41 PM   #9
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

That does not give you the nice 2D array syntax though.
Collapse 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
__________________
Anitarf is offline   Reply With Quote
Old 01-20-2010, 09:57 PM   #10
Tot
†6†
 
Tot's Avatar
 
Join Date: Oct 2008
Posts: 841

Tot will become famous soon enough (53)Tot will become famous soon enough (53)

Default

Quote:
Originally Posted by Anitarf
That does not give you the nice 2D array syntax though.
but works fine and is less to type and less work for the cpu (loopfree!!)

if jh has "real" operators (no blame for vex), you can simulate real arrays, but without...
__________________
Current Projects:
  • Masters Of WarCraft: Some mixture of AoS and RPG
    Terrain: 100%, Coding: 75%, Heroes: 0%, Items: 0%, Creeps: 0%, Upgrades: 0%
  • hunting emos
____________________________________
scheiss kack dreck sausacksau bundeswehr

Last edited by Tot : 01-20-2010 at 10:00 PM.
Tot is offline   Reply With Quote
Old 01-20-2010, 11:10 PM   #11
Ammorth
I blink, therefore I am.
 
Ammorth's Avatar
 
Join Date: Sep 2006
Posts: 1,812

Submissions (10)

Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)

Default

Quote:
Originally Posted by Anitarf
That does not give you the nice 2D array syntax though.
Collapse 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

That's pretty neat. Thanks.
__________________
Ammorth is offline   Reply With Quote
Old 01-21-2010, 12:21 AM   #12
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

With enough hacking and a text macro I think you can have tot's solution AND [][] syntax. I'll leave it as an exercise.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 01-21-2010, 07:13 PM   #13
Tot
†6†
 
Tot's Avatar
 
Join Date: Oct 2008
Posts: 841

Tot will become famous soon enough (53)Tot will become famous soon enough (53)

Default

Quote:
Originally Posted by Vexorian
With enough hacking and a text macro I think you can have tot's solution AND [][] syntax. I'll leave it as an exercise.

??? [][] operators...in vJass???
have i missed something??
__________________
Current Projects:
  • Masters Of WarCraft: Some mixture of AoS and RPG
    Terrain: 100%, Coding: 75%, Heroes: 0%, Items: 0%, Creeps: 0%, Upgrades: 0%
  • hunting emos
____________________________________
scheiss kack dreck sausacksau bundeswehr
Tot is offline   Reply With Quote
Old 01-21-2010, 08:52 PM   #14
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

The trick is to be creative.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 01-21-2010, 09:42 PM   #15
Ammorth
I blink, therefore I am.
 
Ammorth's Avatar
 
Join Date: Sep 2006
Posts: 1,812

Submissions (10)

Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)

Default

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.
Ammorth is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 11:33 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services