Godot Version
v. 4.5.1
Question
Making a mockup webpage game and I can’t see what’s wrong here. Upon pressing the button, “.visible = true” is set for an object. The last line is the code I am trying to implement in a separate function - when combined with the button, it works fine.
func _on_o_nas_button_button_up() -> void:
$"..".visible = false
$"../../ObecnoscONas".visible = true
previous_page.append($"..")
previous_page.append($"../../ObecnoscONas")
$"../../Control/ColorRect/LinkText".text = "display this text"
However, the code won’t change the LineEdit’s textbox when trying to do so using the function below:
func nazwa_linku():
if $"../../ObecnoscONas".visible == true:
$"../../Control/ColorRect/LinkText".text = "display this text"
else:
pass
There is no error showing up, it just seems to not care about the nazwa_linku function.
Additionaly, the above code for the button action is also the only way to obtain a $“../../ObecnoscONas”.visible = true state. So I was hoping on the change of its state, another function should behave accordingly.
I suppose it isn’t checking/seeing the state of “.visible” for some reason?
What am I missing?..
Where is nazwa_linku() located and where/when are you calling it?
It’s all located in one script - it’s the node that’s acting as the main page.
I thought just verifying the .visible == true condition would make it work. I am ofc still very new to this, so let me ask - how could I call it?
LineEdit node itself or parent node being visible or not has no effect on changing LineEdit’s text.
If the node is accesible, you can access and change the text. If it’s not visible, you just don’t see it on the screen, (it’s not rendered to show to the player’s computer monitor). But the text would still change if you code it correctly.
You have two scripts on the screenshot you shared.
If your functions are on the script on node ObecnoscdawidaMain, then it should work
If you are functions are on the script on node ObecnosMain, then it won’t work because the path is not correctly referring to the LinkText.
In general I almost never use node assignment with $“../../ObecnoscONas”…
I mostly use @export var and then assign the node in editor.
You’d have to call nazwa_linku() somewhere after setting $"../../ObecnoscONas".visible = true
For example:
func _on_o_nas_button_button_up() -> void:
$"..".visible = false
$"../../ObecnoscONas".visible = true
previous_page.append($"..")
previous_page.append($"../../ObecnoscONas")
nazwa_linku()
Yeah, as @CyberHermit shows, you have to call the function.
I think your misunderstanding was that nazwa_linku would just automatically run in a reactive way to the test condition. Functions won’t typically run by themselves, unless they are special virtual functions (like _process or _init), and those aren’t reactive either–they run at specific times during the game’s execution only.