Need help storing diffrent struct into one array.

dudeim

New Member
Reaction score
22
Hey,

I'm currently facing a little problem.
I'm having multiple structs that I need to store into one array (I generate the structs with textmacro's except for the last struct D in the example) all those structs have the same variables and variable names also the same methods exist there.
So here is a little example of what I want
JASS:
struct A
string name //this would be set when created to A
endstruct
struct B
string name
endstruct
struct C
string name
endstruct
//however many I want there to be
//now I have another struct which should be able to store the instances from those structs
struct D
sometype array Structs[50] //in this I should be able to store the other structs I tryed using integer but it gave me an error when I did Structs[1].name
endstruct

So how would I do something like this?
 

Dirac

22710180
Reaction score
147
Do this
JASS:
globals
  integer count=0
endglobals
module arraystore
  private static method onInit takes nothing returns nothing
    set D.Structs[count]=thistype.name //i hope the name variable is static
    set count=count+1
  endmethod
endmodule

implement that module inside your structs
 

dudeim

New Member
Reaction score
22
Don't think the typecasting stuff will work for me.
Also the module wouldn't work either I think.
Well I'll give you some more information.
I'm creating buffs using textmacro's and each buff will have it's own struct.
Now I have a new struct that has the ability to get all buffs on a unit, but as each buff has it's own struct although with all the same members I'm having some problems applying the buff to the bufflist (a,b,c are buffs and d is the bufflist which each unit will automaticly get one of).
So that I can retrieve all buffs currently on a unit that is my current problem.
Also the name variable is static:p

Hope this helped some:p
 

luorax

Invasion in Duskwood
Reaction score
67
in this I should be able to store the other structs I tryed using integer but it gave me an error when I did Structs[1].name

That's because integers don't have any members. You must convert them back to the original struct. (typecast)

If all the structs have the same members, and you want to use only those members, you better do this:

JASS:
scope BuffSystem

    struct Buff
        string name
        string id
    endstruct
    
    struct A extends Buff
    endstruct
    struct B extends Buff
    endstruct
    struct C extends Buff
    endstruct
    struct D
        Buff array Structs[50]
        /*
            set Structs[1]=A.create() will work now; and
            set Structs[1].name="Buff A" too.
        */
    endstruct
endscope
 

dudeim

New Member
Reaction score
22
Yeah that would indeed be a good option the only problem is that the structs that are buffs already extend something and I don't think you can extend multiple things right? (it is extending function interface thingies)
 

luorax

Invasion in Duskwood
Reaction score
67
You can't extend more than one thing. But you can do this:

JASS:
struct A
    string name
endstruct
struct B extends A
    integer type
    //You can use this.name too
endstruct
struct C extends B
    //you can use this.name and this.type
endstruct
 

dudeim

New Member
Reaction score
22
Yeah I know that but as I create the structs using textmacro's I automaticly extend them there.
JASS:
textmacro create_Buff takes Name
struct $Name$ extends buffEvents
//all the members and stuff here
endstruct

So all buffs are automaticly extending buffevents
Edit:
can I maybe do something like this:
JASS:
scope BuffSystem

    struct Buff extends buffEvents //so that the Buff struct extends buffEvents and then the buffs themselfes extend buff
        string name
        string id
    endstruct
    
    struct A extends Buff
    endstruct
    struct B extends Buff
    endstruct
    struct C extends Buff
    endstruct
    struct D
        Buff array Structs[50]
        /*
            set Structs[1]=A.create() will work now; and
            set Structs[1].name="Buff A" too.
        */
    endstruct
 

lep

Active Member
Reaction score
8
Just rtfm. It's actually all explained there. If you glance over the TOC you'll even see a point "Extending structs".
 
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