Methods
Methods are just like functions, the difference is that they are associated with the class, also [normal]
methods are associated with an instance (in this case this
)
Once again an example is needed
- this
A keyword that denotes a pointer to current instance,
[normal]
methods are instance methods which means that they are called from an already assigned variable/value of that type, and this will point to it. In the above example we use this inside the method to assignx
andy
, when callingp.move()
it ends up modiffying x and y attributes for the struct pointed byp
.- method syntax
You might notice that method syntax is really similar to function syntax.
- this is optional
You can use a single
.
instead ofthis.
when you are inside an instance method. (For exampleset .member = value
)
Methods are different to normal functions in that they can be called from any place (except global declarations) and that you are not necessarily able to use waits, sync natives or GetTriggeringTrigger()
inside them (but you may use any other event response), you might be able to use them but it depends on various factors, it is not recommended to use them at all. In next versions the compiler might even raise a syntax error when it finds them.