$long/path/to/object.property or func call( after( call(to script?) ) )

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Kalmier

what is the standard protocol for when to use which?

I know some might be obvious like to just turn on or off a display (long path), or needing to access a lot of object properties (func calls).

but what about if I have a large tree that needs 2 things changed per branch? I see either a single script with a lot of long path names, or a lot of little scripts with a lot of small functions.

is there a middle ground or a different option I’m not seeing?

NOTE: I understand each project is different. I’m looking more for guidance, not actually needing anything fixed.

Maybe I’m not understanding but are you talking about the difference between properties and methods?
Also the 2 things changed per branch example would be done using a for loop counting to get_child_count() or get_tree().get_nodes_in_group().size()

Magso | 2020-01-27 17:36

I guess I should mention I haven’t programmed in 20 years. I’m trying to get back into the swing of things. so I’m looking for advice on how to handle this type of situation. I know how I’m doing it feels right, but idk if it’s what’s best, if something new is avail, or even if godot can handle it natively.

let’s say you have a UI menu display that shows/hides features if you do/don’t have something. My update func would have to change the …/StatFrame01/Label.text and then make the …/StatFrame01.visibility = true, or …/StatFrame01.show().

i can use var Node = get_node(…/StatFrame01), but then how do I change Node/Label.text?

I can use the for loops by making an array since I have 10 stats to display, but I guess my question is more about the best scripting protocols for this dynamic menu thing I’m making.

so right now I am using my levels script to call my UI script (b/c there are other UI calls like dialogue), which calls my pause screen (scripts both item and button displays), which calls my items display, which calls functions to v/h boxes. My setup is 1 item on the top, and then columns of 3/3/3 items on the bottom.

the alternative is to have my levels script just reach all the way down my UI’s paths to change things, which isn’t very clean of course.

$User_Interface/Pause_Menu/Items_Display/Animal_Stats/StatFrame01/Label.text = str(Stat01)
$User_Interface/Pause_Menu/Items_Display/Animal_Stats/StatFrame01.show()
$User_Interface/Pause_Menu/Items_Display/Animal_Stats.show()

  • if a v/h box is not .hide() when empty, it makes the display uneven.

even calling a script in …/Items_Display has a lengthy path, or how do I use Node/Animal_Stats.show(), etc?

hope that’s better explained… :slight_smile:

Kalmier | 2020-01-28 01:00

You can set nodes you’ll commonly use as a variable like this

var node = $User_Interface/Pause_Menu/Items_Display/Animal_Stats
for i in node.get_child_count():
    if Stat[i] != null:
        node.get_child(i).get_node("Label").text = str(Stat[i]) #Stat is an array
        node.get_child(i).visible = true
node.visible = true

This would go through all the children of Animal_Stats so there’s no countless lines of long paths and it will ignore the ones with no Stat.

Magso | 2020-01-28 01:58

I do believe get_child is what I was looking for. This will allow me to do some of the things I’ve been avoiding with much ease. Thank you, and sorry for the rustiness.

Kalmier | 2020-01-28 02:25