HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

struct methods

09-10-2008, 02:04 AM#1
Joker
I'm still confused on why methods are better than functions in some cases. Can't a function do everything a method can, or are methods better in some way?
09-10-2008, 02:15 AM#2
moyack
methods are functions, the only difference is that they can be called in a more comfortable way in to a struct variable.

Collapse JASS:
struct vector
   real x
   real y
   real z

   method Set takes real x, real y, real z returns nothing
      set this.x = x
      set this.y = y
      set this.z = z
   endmethod
endstruct

function test takes nothing returns nothing
   local vector V = vector.create()
   call V.Set(10, 20, -30) // here the method allows us to set the values in a more elegant way
endfunction

Methods gives a more readable way to do the things, makes you to code in a more organized way reducing the development time, that's at least my point of view.
09-10-2008, 02:32 AM#3
Here-b-Trollz
Methods also have access to private members of the struct.
09-10-2008, 02:32 AM#4
Vexorian
functions can't access the method's private members.
09-10-2008, 02:37 AM#5
Joker
Damn, wish I used more methods in my map. My codes look ugly :(
09-11-2008, 12:40 AM#6
fX_
methods are inside the struct. theyre associated to whatever the struct is associated to (can be private/public) so it is ezier to tell/define what the method is supposed to be doing/what its supposed to bne working with.
09-11-2008, 01:18 AM#7
Zerzax
My two favorite aspects of methods are (a that they often can just do their job through knowing which instance to manipulate (call struct.run) and that they organize your coding in an efficient and logical manner. It makes more sense to nestle your methods into the right place than have a bunch of functions floating around in your script (IMO).