0 votes

Hello Everyone!

I'm creating a beat'em up game in Godot! I'm trying to test player controls and to do that I start the scene with 3 enemies, and spawn 3 more whenever all enemies are killed.

This is the code for my spawner:

extends Node2D

##########################
# Class Member Variables #
##########################
const ENEMY = preload("res://Enemies/Enemy01/Enemy01.tscn")
const MAX_ONSCREEN_ENEMIES = 4

onready var entities_layer = self.get_node("../EntitiesLayer")
onready var player = entities_layer.get_node("Player")


#############################
# Custom Method Definitions #
#############################
func spawn_enemies():
    var children = entities_layer.get_child_count()
    if children < 2:
        var to_spawn = MAX_ONSCREEN_ENEMIES-children
        for n in range(to_spawn):
            var enemy = ENEMY.instance(true)
            var posx = player.get_pos().x + floor(rand_range(-45,46))
            var posy = player.get_pos().y + floor(rand_range(-11,12))
            enemy.set_pos(Vector2(posx,posy))

            entities_layer.add_child(enemy)
            pass
    pass

###########################
# Engine Standard Methods #
###########################

func _ready():
    randomize(true)

    set_process(true)
    pass

func _process(delta):
    spawn_enemies()
    pass

It works fine when I'm testing the game in the editor, but once I export it, the resulting executable doesn't spawn anything, after I kill the first 3 enemies.

Is there something wrong on the code above? Is it some project settings? How can I try to debug the exported executable to try and find out what's happening?

If you need more information about the project, or want to test it out in the editor yourself, you can find it here on github - http://github.com/vandalk/Beatwo

in Engine by (19 points)
edited by

1 Answer

0 votes
Best answer

Alright! Found out how to debug an exported project from an answer for another question at the forum! You only need to execute your game from the command line to see the debugging happening there!

From there I found out my problem was on the instance() call:

var enemy = ENEMY.instance(true)

That true didn't need to be there and only work on the editor apparently. I don't know why I though I needed that true to be honest. Just erasing it and leaving:

var enemy = ENEMY.instance()

made everything work!

by (19 points)

I completely skipped that "true" there, tbh. I didn't even know you could do that, all code I've seen so far use just .instance().

Glad you found it, good catch. :)

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.