Accesing the base class's variables

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By EIREXE
:warning: Old Version Published before Godot 3 was released.

Hi, my code looks something like this:

func _ready():
	var test = SecondClass.new(4)
	test.method_example()
		
class FirstClass:
	var a
	func _init(a):
		a=a

class SecondClass:
	extends FirstClass
	func _init(a).(a):
		pass
		
	func method_example():
		print(str(a))

However I have not fo und a way to access a from SecondClass, is this even possible?

:bust_in_silhouette: Reply From: supaiku

Hi,

the problem here is that you pass a parameter named a and have a instance field named a. Prefix your variable with self to point to the instance variable (or change the parameter name). Then it will work.

class FirstClass:
var a
func _init(a):
    self.a=a

Yeah, that made it work, thanks!

EIREXE | 2016-07-23 23:44