Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Dumuz |
My problem lies with the last couple lines. This is my first time trying to make a packedscene
in script for use of instancing later. But on this test add_child()
, it keeps failing with this error I put in the title: Invalid call. Nonexistent function ‘instance’ in base ‘int’. I’m not sure what I’m doing wrong here. I’ve tried it without packing the scene and then instancing and it works fine, once. But it won’t add anymore because “the child already has a parent”, so I need to instance this.
func _on_give_Toy_btn_pressed():
var highlight = Button.new()
var empty = StyleBoxEmpty.new()
highlight.rect_min_size = Vector2(100,100)
highlight.set('custom_styles/normal', empty )
highlight.connect("pressed",pet,"_praise",["toy","doll"])
highlight.connect("pressed",self,"_clean_up",[highlight.get_instance_id()])
var highlighted = PackedScene.new().pack(highlight).instance()
$Inv_GUI/inv_cont.get_child(0).add_child(highlighted)
I’m not really familiar with PackedScene
, but your error comes from the fact that the pack()
method returns an Error
, which is just an ENUM. So, this…
PackedScend.new().pack(highlight).instance()
… ends up trying to call instance()
against that returned ENUM value, which is just an INT …
jgodfrey | 2020-02-15 18:17
So that helped, thank you. I put the pack()
method as a standalone and called the creation of the instance when the child is being created:
var highlighted = PackedScene.new()
highlighted.pack(highlight)
$Inv_GUI/inv_cont.get_child(c).add_child(highlighted.instance())
But I’ve run into a new problem now: The buttons are there, but now they don’t do anything. The two connections I made don’t seem to be doing anything anymore, why is that?
highlight.connect("pressed",pet,"_praise",["toy","doll"])
highlight.connect("pressed",self,"_clean_up",[highlight.get_instance_id()])
Dumuz | 2020-02-15 18:40