User:Senka/a bas nije da nas nikad nije bilo/Godot Debugging

From XPUB & Lens-Based wiki

Debugging

Portals

There's a documentation page for portals and rooms [1] but it's outdated (made for Godot 3.5, I'm using 4.3).

Portals to different rooms This needs a lot of reorganizing of the code for it to work... Currently stuck at trying to delete one room once there has been a switch from another (queue_free function not working).

The script is supposed to instantiate a new scene once the body ("Player") enters the portal. After the player has entered the new scene, the previous one is supposed to be deleted with the queue_free function.

Currently I have:

  • A portal (Area3D) with the script:
extends Area3D
var next_scene = preload("res://rooms/room_2.tscn")
var current_scene = preload("res://rooms/room_1.tscn")
func _on_body_entered(body: Node3D) -> void:
   if body.name == "Player":
       if body.in_transition == false:
           body.in_transition = true
           print("something might work")
           var instanced_scene = next_scene.instantiate()
           get_tree().root.get_node("World").add_child(instanced_scene)
func _on_body_exited(body: Node3D) -> void:
   if body.in_transition:
       body.in_transition = false 
The script with all the code that was tried, didn't work and commented out
  • room2 (Node3D) with the script:
extends Node3D 
@onready var player = $Player
@onready var room1 = "res://rooms/room_1.tscn"
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
       player.camera.make_current()
The code ONLY for the room that needs to be instantiated. It creates the room, the player and the camera the player is looking through and swtiched to the new camera of the player
  • the World (root) node (Node3D):
extends Node3D
@onready var room1 = "res://rooms/room_1.tscn"
var room1_scene = preload("res://rooms/room_1.tscn")
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
   if room1_scene != null and is_instance_valid(room1):
       #room1.queue_free()
       var deletion_scene = room1_scene.instantiate()
       deletion_scene.queue_free()
       print("room1 deleted")

No error appears with this version of the code but it doesn't work.

The script for the world node from which I am trying to delete the scene the player left

Question:

  • How to adjust the code to delete the previous room? (While allowing the user to enter back)
  • Can portals refer to/lead to HTML pages? (I would love to link some rooms to bitsy pages if possible)

HTML/itch.io Exporting

Question:

  • If the game is uploaded as an html page, is it better to have the menu as javascript button on top of the game (canvas item) or to have an in-game menu? Would the in-game menu access the in-game mechanism better? (Such as room change)

Rich Text Label