Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Alexandr |
How to redefine an expandable class variable?
Expamle:
class Asd:
var variable = 1
class Dsa extends Asd:
variable = 2
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Alexandr |
How to redefine an expandable class variable?
Expamle:
class Asd:
var variable = 1
class Dsa extends Asd:
variable = 2
Reply From: | Xrayez |
class Asd:
var variable = 1
class Dsa extends Asd:
func _init(p_variable = 2):
variable = p_variable
# somewhere in your code
var dsa = Dsa.new(2)
print(dsa.variable) # should print 2
class Asd:
var variable = 1
class Dsa extends Asd:
func _init(p_variable = 2):
self.variable = p_variable #it does not carry self?
var dsa = Dsa.new(2) print(dsa.variable) # should print 2
ariel | 2018-11-26 19:17
It’s not necessary in this case. self
is needed if you need to distinguish between method’s parameter name and member name:
func _init(variable = 2):
self.variable = variable # notice no `p_` prefix
Xrayez | 2018-11-26 19:24