Godot Version
extends Area2D
class_name Chest
var health := randi_range(5, 10)
@export var javalin : PackedScene
@export var knife : PackedScene
@export var torch : PackedScene
@export var axe : PackedScene
@export var bow : PackedScene
func _process(delta):
if health <= 0:
spawnRngLoot()
func take_damage(damage):
health -= damage
func spawnRngLoot():
var loot = 0
print(loot)
var item
match loot:
# Javalin.
0:
item = javalin.instantiate()
# Knife.
1:
pass
# Torch.
2:
item = torch.instantiate()
# Axe.
3:
pass
# Box.
4:
pass
# Armour
5:
pass
# Score pickup.
6:
pass
if item != null:
item.transform = transform
queue_free()
Question
So what's supposed to happen is that when the chest is destroyed its supposed to pick a random number (I have it set to zero for test purposes), and depending on what number it spawns the corresponding item, but when I destroy it; it doesn't spawn in the item.