Godot Version
4.3
Question
I’m trying to get this code to remove the array item that correlates with the instance_room variable, however, the erase function is not doing that properly? I think this may have to do with it being initialized. The code is as follows:
extends Node3D
# Called when the node enters the scene tree for the first time.
func _ready():
var rooms = [preload("res://Generation/House/rooms/rat_room.tscn"), preload("res://Generation/House/rooms/small_room.tscn"), preload("res://Generation/House/rooms/medium_room.tscn"),
preload("res://Generation/House/rooms/long_room.tscn"), preload("res://Generation/House/rooms/Large_room.tscn")]
var exits = []
for child in $".".get_children():
exits.append(child)
print(exits)
for i in exits:
var current_exit = i
print(current_exit)
var current_location = current_exit.global_position
print(current_location)
var current_orientation = current_exit.global_rotation
print("rotation", current_orientation)
var instance_room = rooms[randi() % rooms.size()].instantiate()
instance_room.set_position(current_location)
instance_room.set_rotation(current_orientation)
add_child(instance_room)
print("Spawning room:", instance_room)
rooms.erase(instance_room)
print(rooms)
#pass
return rooms
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
pass