Why can I not change the value of an exported variable in the inspector?

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

I am a complete beginner, and I am having trouble with a tutorial I am working through.

I have a scrip with the following variable definition:

export(int) onready var health = max_health setget set_health

It shows up in the editor’s inspector as expected. However, when I change the value in the inspector, save the scene, and run my game, the value I changed is ignored, and the original value is used in the game.

Here is the whole script for context:

extends Node

export(int) onready var max_health = 4
export(int) onready var health = max_health setget set_health

signal no_health

func set_health(value):
	health = value
	if health <= 0:
:bust_in_silhouette: Reply From: Inces

You mixed something up.

health var is dependant on maxhealth here, exported health value is overriden with maxhealth. But why do You need to export health, when You already export maxhealth ? Feed only maxhealth to your scene.

I figured out that I shouldn’t have made my variables onready.
Onready variables are initialised after the values from the inspector are loaded, and therefore the values of the variables came from the script, not from the inspector.

MushroomAlien | 2022-08-15 16:25