+1 vote
extends Control

func _ready():
    pass

export(bool) var ShowFutureDesignObjects = false #change to true to show future design objects

var FutureObjects = ["Node1", "Node2", "Node3", "Node4"]


func ShowFutureDesign():
        for Obj in FutureObjects:
            if ShowFutureDesignObjects == false:
                get_node(Obj).visible.hide
            else:
                get_node(Obj).show
in Engine by (93 points)

1 Answer

+1 vote
Best answer

OK, I found what the problem is.

Basically, three things:
1) You never call the function ShowFutureDesign(). Try calling it from the func _ready() function

2) It's .hide() and .show(), actually, not .hide and .show

3) Make sure the get_node() method gets called on the right node. If you try to access the nodes from a subnode, you might have to use the get_parent().get_node(Obj) method or something equivalent.

by (1,888 points)
edited by

Hello, thanks for the comment.

You write :

get_node(Obj).visible.hide

but shouldn't it be:

get_node(Obj).hide

Yes, I actually had them both get_node(Obj).hide, but I was trying to illustrate it's a visible property.

Also, I don't know why this array of yours has strings as members.
That's a good point, get_node looks for the name of the node by string.
ie. get_node("LabelName")

OK, I found what the problem is.

Basically, three things:
1) You never call the function ShowFutureDesign(). Try calling it from the func _ready() function

2) It's .hide() and .show(), actually, not .hide and .show

3) Make sure the get_node() method gats called on the right node. If you try to access the nodes from a subnode, you might have to use the get_parent().get_node(Obj) method. or something equivalent.

I have updated the answer to this. If this is the right answer, please mark it as best so that others can find it too.

JohnnyGames Wow, It works!

Thank you so much I had been struggling with this.

I didn't need the getparent; however I am glad you said that because I had been trying getroot().getnode()
get
children
etc. etc. etc.

Final working code is:

func _ready():
    ShowFutureDesign()

export(bool) var ShowFutureDesignObjects = false #change to true to show future design objects

var FutureObjects = ["StockName", "StockSymbol", "Search", "ExtCostBasisLabel"]


func ShowFutureDesign():
        for Obj in FutureObjects:
            if ShowFutureDesignObjects == false:
                get_node(Obj).hide()
            else:
                get_node(Obj).show()

Can you up vote my question also so people find it?

thanks

Done! Glad it solved your issue.

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.