0 votes

Hi, i have a problem, i have a button scene and a button script. The button is connected in the button script. I have a main scene with a main script and in the script i do:

onready var button = preload("res://button.tscn").instance()

func _ready():

    button.duplicate(1)
    button.global_position = # a random position (the position is not the problem)
    self.add_child(button)

the script works perfect it duplicate the button and set it on the perfect position but if i run the game i get a error the game dont stop but if i will press the button i get this error:

 E 0: 00: 04.882 emit_signal: Error calling method from signal 'pressed': 'Button (object.gd) :: _ on_Button_pressed ()': Method not found ..
   <C ++ source code> core / object.cpp: 1260 @ emit_signal ()

and i dont no what i can do.

please help me.

Godot version 3.2.3
in Engine by (85 points)

1 Answer

+1 vote
Best answer

Just guessing, but I assume you want to change the argument on your duplicate() call from 1 to 5. Looking at the docs here for those flags:

https://docs.godotengine.org/en/stable/classes/class_node.html#enum-node-duplicateflags

A value of 1 causes any attached signals to be duplicated in the new node. A value of 4 causes any attached scripts to be duplicated in the new node.

Since your original node has both a signal and an associated script, you want them both to be duplicated. To do that, just add the values together. So, 1 + 4 = 5.

So, try this:

button.duplicate(5)
by (10,894 points)
selected by

Oh, I just noticed you're not storing the result of your duplicate() call. That call returns a new node. So, you should be doing something like:

var b_copy = button.duplicate(5)
b_copy.global_position = # a random position (the position is not the problem)
self.add_child(b_copy)

Thank you for your answer i think it works. Soo i thought duplicate (1 or 2) means how much I want to duplicate it. but thanks now i understand. Thank you very much

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.