HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Structs and Methods

09-08-2007, 04:04 PM#1
TheSecretArts
okay, im not sure about a few things, but, do struct values have to be initialized, eg, can i do this:
Collapse JASS:
struct Something
     private real VarA
     private int VarB
     private boolean isTrue
endstruct
Would that be legal?
Is there any limit to how many methods can exist in a struct, actually, before that, can methods be put in a struct? IE;
Collapse JASS:
struct Something
     private real VarA
     private int VarB
     private boolean isTrue
     method CheckisTrue takes nothing returns boolean
          if (this.VarA > this.VarB) then
               return true
          else
               return false
     endmethod
     method SetVarA takes real n returns nothing
          set this.VarA = n
     endmethod
     method SetVarB takes integer n returns nothing
          set this.VarB = n
     endmethod
endstruct
And if you can use as many methods as you want, then couldnt an entire system just be one struct? Almost like a programming library?
09-08-2007, 04:11 PM#2
MaD[Lion]
yes an entire system can be on 1 struct, but who would do that, struct is for making things seperated so u can keep better control.
Methods are functions in jass that takes the struct itself and other parameters. so u can have as many methods as u want yes.
And ur first example is legal, just i dont know wat u mean by initialized...
09-08-2007, 04:14 PM#3
TheSecretArts
i mean by initialized that they start with a value
ie:
private real vara = 10
And im making a system that is one struct, it is a new object type that is called projectiles and contains a whole bunch of methods that enact just on them, I just wasnt sure if it was legal becasue i havent tested it with vJASS parser test yet.
09-08-2007, 04:24 PM#4
moyack
yes, it's legal all that you've posted, but I think it's more flexible and readable a library with structs than a single struct with a bunch of data.
09-08-2007, 06:10 PM#5
Captain Griffen
Struct values don't need to be initialised. In fact, referencing them while uninitialised won't cause the thread to even crash, I believe (due to them being on arrays).