Don't quite understand Structs

MagnaGuard

Active Member
Reaction score
49
Well, maybe I'm too young to try to learn this. However, what exactly are they used for? They just seem like globals to me. Also what spells should I try to make using struts? Thanks.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Struct is like a class and member in it are students. Struct is globals with arrays. Each time it called, it will automatically generate a unused array for globals. Struct is for us easy to make stuffs. With struct, you no longer need attach handles to timer. You only need to attach the integer to timer. Hehe, i only 15 years old and i think i am to late to learn it. ;p
 

SerraAvenger

Cuz I can
Reaction score
234
I don't like the "class/students" explanation...
I usually do the "furniture" metaphor : D
Like in:
The struct's class is "chair".
The struct's instance is, for example the chair you are currently sitting on - curChair.
The struct's members do either describe the struct's instance, or the struct's class. For example:
JASS:
curChair.size, curChair.color, curChair.cost, curChair.model //-> describe instance
chair.count (the number of chairs), chair.class ("chair") //-> describe class

The struct also has "methods", stuff that either returns information about the struct or changes the information contained in the struct.
JASS:
call curChair.changeColor( "red" )
call curChair.reduceCost( 15 )
set color = curChair.getColor() // "red"

And for sure there are also methods for the struct's class, like chair.create() (gets a new chair)

What spell to make?
I wouldn't make a spell with a struct right at the beginning.
I'ld make a struct that contains info about a player, like their name, the number of units they have and how much gold they had at the time the struct was created.

Because in order to make a spell work with structs, you need some attachment systems, which you should learn lateron. Players need no attachment systems as you can easily use their player index as array index and store the struct in the index.
like
JASS:
globals
  playerinfo array PlayerInfo
endglobals

//
    call BJDebugMsg( PlayerInfo[ 0 ].name ) // should display player 0 (red)'s name
//


hf and good luck, davey
 

Jesus4Lyf

Good Idea™
Reaction score
397
local MyStruct structVar=MyStruct.create() --> create returns an integer which is then stored in structVar.
structVar.field --> returns MyStruct_Field[structVar] (loads from an array)

That's all it does. Integers and arrays. It's a way of associating a bunch of values.

It's nice for attaching a bunch of values to an object because you only have to attach one integer.
 
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