Changing a global variable value from another script

Godot Version

Godot-4

Question

im basically trying to make the current scene change using a func named load_level_scene_index(that iknow it works)when a dialgue stops i am already using the func on_dialogue_ended(that also works because the print inside is working) but it seems like i can’t use load_level_scene_by_index in this code so what shoud i do? thanks

Your print on line 7 runs? Do you get any errors in the output or debugger? What does the function load_level_scene_by_index look like?


Make sure to paste code instead of screenshots

hi yeah the print runs and theres no output errors related here’s the code for load_level_scene_by_index:

“”"func load_level_scene_by_index(index: int) ->LoadedScene:
if (index< 0 or index>=loadable_scenes.size()):
return null
return load_level_scene(loadable_scenes[index], index)

func load_level_scene(scene_to_load: Loadablescene, index:int) → LoadedScene:
if (not scene_to_load.scene.can_instantiate()):
return null
if (current_scene != null):
current_scene.scene.queue_free()
current_scene=null
var new_scene : Node = scene_to_load.scene.instantiate()

“”"

the func loaad_level_scene_by_index actually works when i use it in it’s own script but when i try to use it in the npc script it doesn’t seem to work

Is there any chance your loadable_scenes.size() is less than or equal to 1? If you only have 1 loadable scene then your index will be out of bounds.

It seems like all of your return null statements should produce errors, you could use push_error to print out an error message before returning null, that should help highlight what the issue is, rather than silently failing.

yeah i seems like the loadable scenes size is 0 thanks