kidscancode/godot_tutorials

Lesson Part 5_ gems will not respawn

Javolikis opened this issue · 3 comments

Towards the end of this tutorial, I have encountered an issue with the respawn of the gems after initial acquisition. They will not pop up after I touch all 10 gems.

extends Node

onready var gem = preload("res://gem.tscn")
onready var gem_container = get_node("gem_container")

var screensize
var score = 0
var level = 1

func _ready():
	randomize()
	screensize = get_viewport().get_rect().size
	set_process(true)
	spawn_gems(10)
	
func process(delta):
	if gem_container.get_child_count() == 0:
		level += 1
		spawn_gems(level * 10)
	
func spawn_gems(num):
	for i in range(num):
		var g = gem.instance()
		gem_container.add_child(g)
		g.set_pos(Vector2(rand_range(100, screensize.width-100),
		rand_range(100, screensize.height-100)))

I edited your post - to format a code block, use three backticks: ``` The "Styling with Markdown" link at the bottom of the comment window has all the details.

I don't see anything wrong with the code at first glance. The respawn is triggered by the gem_container node having no children. Does your gem_container node have any other children by chance?

I dont think so. It's the child of "Main" node.
Oh I placed the backticks in here. New to the site and program but with some coding experience. It seems I get stuck in coding because it changes rapidly but Godot so far seems to be not as chaotic thus far.

I figured it out! Yaaaa! thank you for your support, cbscribe! Needed a "_" before process. When I typed it initially it created an error but now it works. lol!