Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | MaaaxiKing |
In BaseGame.gd there should be the do_something() function. I want to write lines in this function from another script.
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | MaaaxiKing |
In BaseGame.gd there should be the do_something() function. I want to write lines in this function from another script.
Reply From: | blockchan |
Yes it’s possible and called “inheritance”
create do do_something
in SecondScript.gd, then at the top of BaseGame.gd
:
extends SecondScript
I’d have to to extends “res://Scripts/Second.gd”, however this isn’t what I wanted to have. I’ll give you an example:
BaseGame.tscn
Control
Container
Second.tscn
Node
Control (inherited from BaseGame.tscn)
BaseGame.gd
func do_something():
pass
func _ready():
print ($Control.rect_size)
Second.gd
$Control.do_something.add_lines("print("Hello")")
(this is just an example how it could work)
Of course, the added code wouldn’t be seeable for us, it would be there like if you did $Control.add_child(Sprite.new)
If Second.gd extended BaseGame.gd, $Control wouldn’t be found.
MaaaxiKing | 2020-05-13 15:44