Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | lawric_ |
Hi, when working on my level selection system i was trying to make unvisited levels locked, for that i used a array where each item is array with the level path and a bool.
var level_list = [
["res://Scenes/levels/Level1.tscn", true],
["res://Scenes/levels/Level2.tscn", false],
["res://Scenes/levels/Level3.tscn", false],
["res://Scenes/levels/Level4.tscn", false],
["res://Scenes/levels/Level5.tscn", false],
["res://Scenes/levels/Level6.tscn", false],
["res://Scenes/levels/Level7.tscn", false],
["res://Scenes/levels/Level8.tscn", false],
["res://Scenes/levels/Level9.tscn", false],
["res://Scenes/levels/Level10.tscn", false],
["res://Scenes/levels/Level11.tscn", false],
["res://Scenes/levels/Level12.tscn", false],
["res://Scenes/levels/Level13.tscn", false],
["res://Scenes/levels/Level14.tscn", false],
["res://Scenes/levels/Level15.tscn", false],
["res://Scenes/levels/Level16.tscn", false],
["res://Scenes/levels/Level17.tscn", false],
["res://Scenes/levels/Level18.tscn", false],
["res://Scenes/levels/Level19.tscn", false],
["res://Scenes/levels/Level20.tscn", false],
]
When a scene is entered i run a function that checks if the current scene file path is in this list, if so, update the corresponding bool.
func update_level_list():
var current_level_filepath = current_level.get_filename()
for level in level_list:
if current_level_filepath == level[0]:
level[1] = true
For some reason that comparison returns false, even though when i print both values they are the same in the output window.
Unsure what current_level.get_filename()
is here but it must differ from what is in the list in some way (or the list is incorrect).
The following works:
# consider populating the list auto-magically using a directory object
var level_list = [
["res://Scenes/levels/Level1.tscn", true],
["res://Test.tscn", false],
]
# scene name is 'res://Test.tscn'
var current_level_filepath = get_tree().current_scene.filename
for level in level_list:
if current_level_filepath == level[0]:
print("matched")
spaceyjase | 2022-01-07 09:44