#+title: Section 03 - Lesson 13, 14 | Spawn Timer, Spawning gems
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../../_share/media/css/godot.css" />

* Links
- [[../../toc.org][TOC - Godot Notes]]
- [[https://www.udemy.com/course/jumpstart-to-2d-game-development-godot-4-for-beginners/learn/lecture/45070483#announcements][S03:L24.13 - Spawn Timer]]
- [[https://www.udemy.com/course/jumpstart-to-2d-game-development-godot-4-for-beginners/learn/lecture/45070485#announcements][S03:L25.14 - Spawning Gems]]

* Notes

** removing connected nodes
- nodes that are connected must be disconnected before deletion
- otherwise strange things happen

** Timing
- add a child node
- search for Timer

*** properties
- autostart: whether it starts as soon as scene is ready in tree
- one shot: time once and stop
- wait time: the actual time it goes

*** signals
- timeout
  - got to Inspector->Node
  - timeout emits a signal when the wait time hits zero

** Spawning Gems

Put the following in the script that you want to create nodes in based on a scene:

#+BEGIN_SRC gdscript
@export var gem_scene: PackedScene
#+END_SRC

*** terms
- =@export=
  - makes the variable accessible and modifiable from the Godot editor
  - allows assigning variables through the interface

    #+ATTR_HTML: :width 300px
    [[file:../../_share/media/img/albert/section03/S03_L14_EX01.png]]

- =PackedScene=
  - resource that holds a scene in a packed, ready to load state

*** what it does
allows us to create instances of the scene

- drag a scene into the property in the inspector
- call instance

#+BEGIN_SRC gdscript
func spawn_gem() -> void:
	var gem_instance = gem_scene.instance()
	add_child(gem_instance)
#+END_SRC

** how to explicitly assign the type of a custom script
- in the script near the top type in
  #+BEGIN_SRC gdscript
  class_name CustomName
  #+END_SRC

- then override on assigning the value
  #+BEGIN_SRC gdscript
  var new_gem: CustomName = gem_scene.instantiate()
  #+END_SRC
