GLBasic forum

Main forum => GLBasic - en => Topic started by: MrTAToad on 2010-Oct-08

Title: Self
Post by: MrTAToad on 2010-Oct-08
I noticed in the latest update that self isn't needed when accessing other extended types, so :

Code (glbasic) Select
TYPE Tb
FUNCTION go%:
DEBUG "here"
ENDFUNCTION
ENDTYPE

TYPE Ta
a%
z AS Tb
FUNCTION moo%:
z.go()
ENDFUNCTION
ENDTYPE

LOCAL p AS Ta

p.moo()

compiles and runs fine.  However, trying to do anything with a% without using self and there is a compiler error...
Title: Re: Self
Post by: Kitty Hello on 2010-Oct-08
uh huh.
Does it work with self.foo()? If so, I'd stay that way. It's safer for future updates.
Otherwise, if you have a global function "foo", how would I know which one to call?
Title: Re: Self
Post by: MrTAToad on 2010-Oct-08
Functions called within the same type need Self :

Code (glbasic) Select
FUNCTION test%:
moo()
ENDFUNCTION


wont compile.

Using :

Code (glbasic) Select
self.z.go()

works fine