If your collectables
is array of load("*.tscn")
scenes, it can't be Node2D
. When load
loads scene, it will be PackedScene
that have instance
method.
As for coin spawning function, I am still suggesting usage of int
variable as switcher because it is faster than checking types of scenes (your method is working, but it is not optimal).
var coin_type = randi()%collectibles.size()
var coin = collectibles[coin_type].instance()
if coin_type == 0:
coin.connect("coin_collected", self, "_on_coin_collected")
else:
coin.connect("carrot_collected", self, "_on_carrot_collected")
This code is simply cleaner and faster.