Use a script's variable on the editor's inspector.

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

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”.

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!

:bust_in_silhouette: Reply From: LoneDespair
# 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)
:bust_in_silhouette: Reply From: DivinePart
# Use '@export' keyword to make a variable Inspector Accessible
@export var SPEED = 300.0
1 Like