0 votes

Im trying instance the Spaniard Enemy Scene to my Enemy Node to be a child of my Battle Scene so i can access the AnimPlayer but it keeps initilizing the variable before the scene gets instanced and crashes.
How can i make it so that it will initialize the variable after my scene has been instanced

extends Control

#ENEMYTYPE ONREADY
onready var SPAWN=$Enemy
onready var Spaniard=preload("res://Scenes/Spaniard_Enemy.tscn")

#PLAYER/ENEMY ONREADY
onready var Player=$Player/Player
onready var Enemy=$Enemy/Enemy
onready var PlayerAnim=$Player/Player/Sprite/Animate
onready var EnemyAnim=$Enemy/Enemy/Sprite/Animate

#QnA ONREADY
onready var QnA=$QnA

#VARIABLES
var num

func _ready():
    var instance
    if Ctrl.Level==1:
        instance=Spaniard.instance()
        $Enemy.add_child(instance)
    set_process(true)

func _process(delta):
    if PlayerAnim.current_animation=="Hurt" or EnemyAnim.current_animation=="Hurt" or PlayerAnim.current_animation=="Attack" or EnemyAnim.current_animation=="Attack" or PlayerAnim.current_animation=="Dead" or EnemyAnim.current_animation=="Dead":
        get_node("Choice1").disabled=true
        get_node("Choice2").disabled=true
        get_node("Choice3").disabled=true
        get_node("Choice4").disabled=true
in Engine by (398 points)
edited by

I can't figure what do you mean, show us the error shown in the debugger.
(take a SS of your godot window if you can)

Also, as a suggestion, change your _process() content to the next code to be more readeable:

func _process(delta):
    var animations = [PlayerAnim,EnemyAnim]
    var anim_states = ["Hurt","Attack","Dead"]
    var choice_nodes_to_disable = [$Choice1,$Choice2,$Choice3,$Choice4]

    for anim in animations:
        if anim.current_animation in anim_states:
            for choice in choice_nodes_to_disable:
                choice.disabled = true

Please log in or register to answer this question.

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 webmaster@godotengine.org with your username.