Structs extends, what can they all be used for ? :S

Komaqtion

You can change this now in User CP.
Reaction score
469
Hello :D

I have now been coding with vJass for quite some time, but there are still a huge amount of different stuff which I have never used myself, such as delegate, modules, interfaces, and many of the different prefixes like [ljass]stub[/ljass] or such (That might not be the most important one, but itäs one of them XD).

Ok, so to my actual question now.
I know that structs can extend arrays to be usable as arrays, but one things I have never used here is other types of extends :S

What can be the benefits of extending other stuff, let's say [ljass]unit[/ljass] or [ljass]player[/ljass] ?
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
No...
JASS:
struct Human
    integer age
endstruct
struct Adult extends Human
    boolean isMarried
endstruct
struct Kids extends Human
    integer mathsMark
endstruct

When you allocate either Adult/Kids, their index will be allocated from Human, but not from the allocator in struct itself.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
I know how you can extend other structs, but what about other stuff (As I said) ?
 

the Immortal

I know, I know...
Reaction score
51
Erm, you can't extend native types. Only other structs and "arrays", although the latter simply means the struct will act as an array and not create automatically allocate/deallocate methods.

Structs extending arrays are used when you don't use (de)allocates - when indexing objects, when willing to write your own allocator or something similar.

Structs extending other structs are used when.. well, you have a type of object that specifies another type. Like 'Kid' is a type of 'Human'. When kid extends human, and you 'create' a new kid (lolz..) you will have access to all variable members in Human and all methods and such that Human has. So calling [ljass]Kid.age[/ljass] will be perfectly fine.
 

Bribe

vJass errors are legion
Reaction score
67
It would be nice to be able to extend both an array and an interface.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
For the extending the native thingy, I think you meant the dynamic array.
JASS:
type PlayerArray extends player array [6]
//The methods are just like struct.
// PlayerArray.create() -> instance
// set vars[0] = Player(0)
// vars.destroy(), for destruction.
// Member :
// PlayerArray.size -> return size of array.

It is useful for structs with extended array, like AIDS struct.
JASS:
struct UnitData extends array
    real array pos [3] //x,y,z
    //! runtextmacro AIDS()
endstruct
//Jasshelper does not allow this.

Solution
JASS:
type RealArray extends real array [3]

struct UnitData extends array
    RealArray pos

    method AIDS_onCreate takes nothing returns nothing
        set .pos = RealArray.create()//Initialize the dynamic array.
        set .pos[0] = 0.//set the value to 0.
    endmethod

    method AIDS_onDestroy takes nothing returns nothing
        call .pos.destroy()//Destroy the dynamic array when unit is deindexed.
    endmethod
    //! runtextmacro AIDS()
endstruct
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top