0 votes

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:
        emit_signal("no_health")
Godot version 3.4.4
in Engine by (15 points)

1 Answer

+1 vote
Best answer

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.

by (8,097 points)
selected by

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.

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.