Can I emit a signal within the same code and script?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Cobaltiz

I want to make a text-based rpg kinda game. So I need to check wether the player has was in a scene already, if yes, then the previous room should change. I tried using bool variables but I will need this again in the future and it’s hard making 5 if’s every time just to check something.
I want to know if it’s possible to emit a signal when the player is in a room. I can’t connect signals from the node panel because I only have one node that I am working with.

:bust_in_silhouette: Reply From: Wakatta

Signals are nice but arrays are better. Well in this use case anyway.

var visited = Array()

func _entered_tree():
    var scene = get_tree().get_current_scene()
    if  scene.name in visited:
        change_room()
    else:
        first_entry()
        visited.push_back(scene.name)

The above assumes you’re using changing scenes using get_tree().change_scene() however you can easily retailor it as required

Will this work if currently I only have one scene and just couple of nodes I am working with?

Cobaltiz | 2022-03-29 13:19

Never mind I got it to work thank you a lot.

Cobaltiz | 2022-03-29 13:33