0 votes

Im making this incremental game which i want to make infinite buttons for, and for that im using a for loop to make a lot of buttons at once, but the name i set for the button (which matters in my code for determining the price and stuff) turns all wierd, for example i give it a name of '1' because its the first button, godot produces me '@[email protected]' and that screws up all my code.
Can anyone help please?

Instancing code:

for item in range(len(copy_dict['default_costs']['Multiplier'])):
    var new_button = multi_button_scene.instance()
    new_button.get_node('Give').text = "+" + get_notation(copy_dict['default_costs']['Multiplier'][str(item + 1)][1]) + " Multiplier"
    new_button.get_node('Cost').text = "$" + get_notation(copy_dict['default_costs']['Multiplier'][str(item + 1)][1])
    new_button.name = str(item + 1)
    $Buttons/Multi/VBoxContainer.add_child(new_button)

Here is the dictionary that is uses (i dont know if you need it):

var default_costs = {
'Multiplier': {
    '1': [Big.new(0.1, 0), Big.new(10, 0), Big.new(0, 0)],
    '2': [Big.new(0.3, 0), Big.new(60, 0), Big.new(0, 0)],
    '3': [Big.new(0.7, 0), Big.new(550, 0), Big.new(0, 0)],
    '4': [Big.new(1.5, 0), Big.new(1750, 0), Big.new(0, 0)],
    '5': [Big.new(2.75, 0), Big.new(5500, 0), Big.new(0, 0)]
}
Godot version 3.5.1 stable
in Engine by (14 points)

It generates a unique name when it instances a class.

1 Answer

0 votes

Names must be unique within a common parent. So, you can't name multiple nodes 1 if they have the same parent. Well, you can, but (as you see) Godot will append some additional info to ensure their uniqueness.

A few tips...

  • When you call add_child(), you can pass in true as a second argument to cause the generation of a more legible name (essentially, with no @ signs).
  • If you pass that 2nd arg, and provide truly unique names within a parent, I think Godot will keep them as-is.

Another option would be to not care about the assigned name and instead just store it (whatever it is) along with other interesting node info for future reference...

by (19,316 points)
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 Frequently asked questions and 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 [email protected] with your username.