Hi all. I'm an absolute beginner here with very basic knowledge in coding. I am creating my first game. It is like an endless runner with random spawns of obstacles moving at different speed from top (out of screen) to bottom (exit screen). There are different types of obstacles and each of them have their own speed. These same few obstacles are used in different scenes but they are positioned differently.
Everything was going well for me until I reached this weird problem... I managed to get the same few obstacle scenes to be randomly instanced but it doesn't seem to work every time. Some times it works endlessly, some things when I closed it and reopen, it doesn't work at all or it just works for a few spawn and then it just stops instancing.
Appreciate it if anyone could advise me on this? Is it because my codes aren't ideal or is it because of queue_free or the clash of the same instanced scene names, etc.? Thanks a bunch :)
Sample of my codes in my main scene's script:
const mobs_1 = preload("res://Mobs_1.tscn")
const mobs_2 = preload("res://Mobs_2.tscn")
const mobs_3 = preload("res://Mobs_3.tscn")
var new_mobs_1 = mobs_1.instance()
new_mobs_1.position.x = rand_range(25, 480)
var new_mobs_2 = mobs_2.instance()
new_mobs_2.position.x = rand_range(25, 260)
var new_mobs_3 = mobs_3.instance()
new_mobs_3.position.x = rand_range(25, 195)
var randomNum = randi()%4 + 2
if randomNum == 1:
if randomNum == 2:
if randomNum == 3:
# When Player exits Area2D of obstacle scene, this signal is called. When obstacle scene's VisibleNotifier exits scene, queue_free().