Hello!
I'm having some problems with script inheritance.
I have one base script Object.gd
(only the relevant part) :
extends Node2D
class_name ObjectBase
#Signal when click on the Area2D
func _on_Area_input_event(viewport, event, shape_idx):
if Input.is_action_just_pressed("left_click"):
print("click") #I get this printed so the signal is received normally
if GLOBAL.game_mode == 1: #Easy mode
_show_choices()
else: #Normal mode
_choice_click(0)
func _show_choices():
pass #Not implemented yet
func _choice_click(choice_id):
if choice_id == 0: #Look
if have_closeup:
_closeup()
else:
#Connect this to the Part's root
emit_signal("show_text", look_text)
else:
_choice_logic(choice_id)
func _choice_logic(choice_id): #Abstract, should be implemented in the instance's script
pass
So now I create an instance of Object.tscn
(which contains nodes with connected signals), attach a new empty script inherited from Object.gd
.
But it does something weird at runtime:
When I trigger the "Area2Dinputevent" signal in the instanced object, the function _on_Area_input_event()
actually triggers too, but it doesn't call _show_choices()
or _choice_click()
when it should, it just run past them when I debug, which I can't understand.
Is this a bug or is it intentional? In both cases, how can I make the script call the functions I need without rewriting them in each instance's script?
Thanks.
PS: I'm on Godot 3.1 stable.