1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The raddest synthwave tracks were chosen - Check out our Music Contest #12 - Results and congratulate the winners!
    Dismiss Notice
  4. The poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  5. Travel to distant realms and encounter scenes unknown to the common folk. The Greatest of Adventures is upon us with the 8th Cinematic Contest. Join in on a fun ride.
    Dismiss Notice
  6. The 18th Icon Contest is ON! Choose any ingame unit and give him/her Hero abilities. Good luck to all.
    Dismiss Notice
  7. Contestants are to create a scene set in the Stone Age. Come and see what you can come up with. We wish you the best of luck!
    Dismiss Notice
  8. Colour outside the lines! Techtree Contest #13 is a go. The contest is optionally paired.
    Dismiss Notice
  9. Greetings cerebrates, our Swarm needs new spawners that will have numerous children. Join the HIVE's 31st Modeling Contest - Spawners and Spawned! The contest is optionally paired.
    Dismiss Notice
  10. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[vJASS] Just arrays

Discussion in 'Triggers & Scripts' started by Krogoth, Oct 12, 2012.

  1. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    Code (vJASS):
    type my_array extends integer array
    struct A
         my_array A_array
         method destroy takes nothing returns nothing
              call A_array.destroy()
         endfunction
    endstruct
    Is it needed?

    Or I can do this:
    Code (vJASS):
    struct A
         integer array A_array
    endstruct
    And everything will be fine?
     
  2. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,162
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    You need to define a max size for the array, such as

    Code (vJASS):
    struct A
        integer array A_array[50]
    endstruct


    Note that the max instances for the struct will be 8190/[size of largest array in the struct], unless you define a higher instance limit for the struct.
     
  3. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Note that you won't be able to use the dot syntax if you define it as an integer. Technically you can if you do A(int) or thistype(int) but that usually gets clunky. So if you want, you can just define it as:
    Code (vJASS):
    struct A
        thistype array A_array[50]
    endstruct


    The keyword
    thistype
    represents the type of the struct that the variable is in. So in the case above, it would be type
    A
    . While
    thistype
    was mostly intended for use in modules, it can be useful in other cases as well. I usually just use thistype to define variables of a struct type unless I need to refer to a different struct than the one it is already in.
     
  4. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    I can declare type extending integer and it seems to be fine with dot.

    Thank you guys, but my question is most about destructor. If struct has unit, location, trigger variables they should be set null upon destroy as I have seen in a lot of spells otherwise it leaks. And my question is actually should I destroy integer/unit/location/trigger arrays (it seems very logic, isn't?)? What should I set null if I destroy arrays to prevent any leak? Like...
    Code (vJASS):
    private unit u
    ...
    u.destroy()
    set u = null
    for...
    Code (vJASS):
    private integer array i[1023]
    ...
    //???
    and...
    Code (vJASS):
    private unit array u[1023]
    ...
    //???

    For using dot syntax I suggest...
    Code (vJASS):
    type my_integer_array extends integer array[1023]
    type my_unit_array extends unit array[1023]

    ...that should replace arrays above.
     
    Last edited: Oct 14, 2012
  5. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    Bump. :p

    edit
    Solved. Found answer here.
     
    Last edited: Oct 15, 2012