0 votes

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.

in Engine by (36 points)

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()

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.

$UserInterface/PauseMenu/ItemsDisplay/AnimalStats/StatFrame01/Label.text = str(Stat01)
* if a v/h box is not .hide() when empty, it makes the display uneven.

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

hope that's better explained... :)

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.

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.

Please log in or register to answer this question.

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.