Godot Version
4.7.2
Question
Hi everyone, I tried to find an answer by searching the forums but came up empty. It’s my first post as well so apologies for any mistakes.
I am making a sci-fi rpg where the player’s ship travels to different planets/locations. I’m trying to make it so that the airlock of the ship (which is the ShipLevelTransition) changes the target level based on what planet the player selects from a map ui in another scene.
This is my map UI where that planet_scene is set:
class_name Planet extends CanvasLayer
@onready var go_to_planet_button: Button = $Control/GoToPlanetButton
@export_file("*.tscn") var planet_scene: String
@export var target_transition_area: String = "LevelTransition"
func _on_go_to_planet_pressed() -> void:
go_to_planet_button.pressed.connect(load_next_planet)
pass
func load_next_planet() -> void:
GalaxyMap.hide_planet_information()
GalaxyMap.hide_menu()
GalaxyMap.traveling_to_planet(planet_scene, target_transition_area)
This is my galaxy map autoload:
extends CanvasLayer
signal planet_changed
func traveling_to_planet(planet_scene: String, target_transition_area: String) -> void:
planet_changed.emit(planet_scene, target_transition_area)
##ShipLevelTransition connects to this signal
pass
In my ShipLevelTransition script, these are the relevant parts and looks like this in the editor:
@tool
class_name ShipLevelTransition extends LevelTransitionInteract
@export_file("*.tscn") var level #want to be able to change this via the planet_scene passed in from the map UI.
@export var target_transition_area: String = "LevelTransition"
func _ready() -> void:
super()
GalaxyMap.planet_changed.connect(_player_entered)
func player_interact() -> void:
_player_entered(PlayerManager.player)
pass
##handles the level change as the player enters the area2d
## target_transition_area is just the name of the target node
func _player_entered(_player: Node2D) -> void:
if level == null:
level = planet_scene
LevelManager.load_new_level(planet_scene, target_transition_area, get_offset() )
pass
func _on_area_entered(_a: Area2D) -> void:
PlayerManager.interact_pressed.connect(player_interact)
pass
Currently, when the player interacts with the airlock, the game crashes and I get this error:
Error at (16, 17): Identifier "planet_scene" not declared in the current scope.
I’ve been looking at this problem for the whole day and I think I’m a bit lost at this point. It’s clear that planet_scene is getting lost somewhere along the signal chain but I’m not sure where. Please let me know if you know have an answer and I’m definitely open to trying a different method to solving this if needed.
