0 votes

Hello! I am currently trying to get a hang of some basic in Godot features (I am a complete beginner), but I have run into a problem and I can't find any solution online.

Right now, I have two buttons in my "game": "Bed" and "Work". To go to work, you have to get up first. I wanted to set up things so two different messages may appear after pressing "Work", depending on whether "Bed" was pressed before. This is the code I used in singleton:

extends Node
var gotUp = 0
func _on_Bed_pressed():
    gotUp = 1

The code for the message that appears if "Bed" wasn't pressed:

extends RichTextLabel
var dialog = ["You need to get up first."]
var page = 0
func _ready():
    set_bbcode(dialog[page])
    set_visible_characters(0)
    set_process_input(true)
func _on_Work_pressed():
    if scn_house.gotUp == 0:
        set_visible_characters(get_total_character_count())

The code for the message that appears if "Bed" was pressed:

extends RichTextLabel
var dialog = ["You went to work."]
var page = 0
func _ready():
    set_bbcode(dialog[page])
    set_visible_characters(0)
    set_process_input(true)
func _on_Work_pressed():
    if scn_house.gotUp == 1:
        set_visible_characters(get_total_character_count())

Unfortunately, the function in the singleton doesn't seem to work. The last message ("You went to work") never appears and this code

func _on_Work_pressed():
    print(scn_house.gotUp)

always prints "0". What am I doing wrong? Any help will be appreciated.

in Engine by (18 points)

because you put "extends Node" in your singleton's script, now it is considered as a node and you can refer to your "gotUp" variable from any script by using command like this :

get_node("/root/global").gotUp = 1;

(if your singleton is called global.gd)

Thank you, I got it to work :)

1 Answer

0 votes

Looks like you didn't connect the singleton function to the button signal. You can add a script to the "Bed" and call the singleton function when the button is pressed.

by (14 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.