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 The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top