• Home
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Darkly)
  • No Skin
Collapse
Godot Community

Godot Community

using strings as node names.

Scheduled Pinned Locked Moved Ask
3 Posts 2 Posters 35 Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MechroJesterundefined Offline
    MechroJesterundefined Offline
    MechroJester
    wrote on last edited by
    #1

    im new to godot and ive figured out how to transfer my other coding experience over but one thing is racking my brain and i dont know if its because it can not be done or because im using the wrong nomenclature.

    i have a dictionary that contains the names of buttons in the tree and an 1 or a 0 for if they should be toggled visible or not. the reason for this is that i would like to make a for loop that will show or ignore buttons on first load under _ready depending on they are set to 1 in the dictionary.

    so basically all i want to do is a variant of this
    $Button2.show()

    but i want the button node name "Button2" to come from the dictionary so something like

    for item_name in dict_toggles:
    temp = item_name
    ...
    ... #other code
    if ...
    $temp.show()

    in this case temp = "Button2" but as much as i have searched i can not find an answer or a "no you cant do this"

    if anyone can help or point me to an example or just give me a no it cant be done that would be great thank you.

    1 Reply Last reply
    1
  • Chris Bickellundefined Offline
    Chris Bickellundefined Offline
    Chris Bickell
    wrote on last edited by
    #2

    If i understand you correctly what you want is to use get_node instead of the $ shorthand, something like get_node("$/root/YourGame/Buttons/" + temp).show()

    1 Reply Last reply
    1
  • MechroJesterundefined Offline
    MechroJesterundefined Offline
    MechroJester
    wrote on last edited by
    #3

    Amazing. That is where I was getting confused since when I looked up $ everything said it was get_node. The only thing I had to change from what you posted was remove the $/root/ then put the grid container name in and it worked perfect.

    func _ready():
    for item_name in dict_toggle:
    var toggleArray = dict_toggle[item_name]
    var toggle = toggleArray[0]
    if toggle == 1:
    get_node("GridContainer1/" + item_name).show()

    1 Reply Last reply
    0

© 2023 Godot Community
Privacy - Terms - Contact

  • Login

  • Don't have an account? Register

Powered by Godot Community
  • First post
    Last post
0
  • Home
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Login

  • Don't have an account? Register