0 votes

Hi! I'm new to Godot and I've been asking myself a question for the past two days about the editor's inspector a script's variables:

Is there a way to use a variable declared on a script inside the editor's inspector?

For example, I would like to replace the static "Label" text with a exported variable named "label_text".

enter image description here

This exported variable belongs to a script attached to the Label's grandparent node:

= PanelContainer (the variable is declared in the script attached to this node)
== VBoxContainer
=== Label (i want to use the variable in here)

Now, why do I want to do this?

First: this nodes are a scene that I saved in order to re-use code. It is a EditLine + Label that I want to use in many different forms. Now, I'm exporting a variable named "label_text" in order to assign the Label's node text while instatiating it.

That whole thing work just fine and I'm able to use this scene on my forms, but there is a small problem. Everytime I use my scene, it looks like this on the editor:

enter image description here

Yes, it displays the default values that I've set on the scene itself. So, if I employ this scene 10 times, there will be 10 elements that look exactly the same on screen. Example:

enter image description here

Is there any solution for my problem? Thanks in advance and sorry for my bad english!

Godot version 3.2.3
in Engine by (12 points)

1 Answer

0 votes
# Single-line input
export var label_text : String

# Multiline input
export(String, MULTILINE) var description : String

# Other example, this is a float that defaults to 64.0
export var hp := 64.0

If you want your changes to reflect immediately on editor, upon changing

tool

extends Label

export var mana := 498 setget set_mana

func set_mana(new_mana : int) -> void:
    mana = new_mana
    text = str(new_mana)
by (394 points)
edited by
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 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 webmaster@godotengine.org with your username.