+2 votes

I am making a quiz game and i want to show a sprite("this_image") that contains an image when the correct answer is pressed and then changes question.
what i am doing is this:

func _on_lbl_answer1_pressed():
    if(oi3 == correct_answer):
        correct_answer()
        this_image.show()
        Globals.get("array_pergunta").append(i+1)
    elif(oi3 != correct_answer):
        wrong_answer()
    i+=1
    generate_table()

func generate_table():
    if(i>=dict.size()):
         get_tree().change_scene('res://Scenes/Scoreboard_M.tscn')

    else:
         this_image.hide()
         var k = dict[keys2[i]]
         correct_answer = k["res_c"]
         lbl_question.set_text(k["question"])

    randomize()
    for i in range(keys.size()):
        var random_index = randi() % keys.size()
        var k1 = keys[i]
        var k2 = keys[random_index]
        keys[i] = k2
        keys[random_index] = k1       



    lbl_answer1.set_text(k[keys[0]])
    lbl_answer2.set_text(k[keys[1]])
    lbl_answer3.set_text(k[keys[2]])
    lbl_answer4.set_text(k[keys[3]])
    oi = lbl_answer1.get_text()
    oi1 = lbl_answer2.get_text()
    oi2 = lbl_answer3.get_text()
    oi3 = lbl_answer4.get_text()

The code above in fact shows the image when i press the correct button and then changes the question but the problem is the image stays visible and i would like to "turn it off" as soon as the question change.

Is there away to do this?

PS: if needed i will provide the rest of the code

in Engine by (31 points)
edited by

You are showing the image in func _on_lbl_answer1_pressed() and calling generate_table() where it immediately gets hidden again. You will need a timer if you want to show it for a given amount of time before hiding it again. Alternately, you can wait for the user's input for the next answer and hide it then.
I hope I'm understanding your intentions properly.

1 Answer

+1 vote

Sure. Just use

this_image.hide()
by (312 points)

i did try that method before but it doesn´t work, i guess because the show and hide command both "go down" one right before the other the moment the question changes and the result is just "nothing happens"

even if i put the "thisimage.hide()" on the function that generates the next question the problem remains, i guess it would need some kinda delay that shows the "thisimage" and then change question.

I thought there must be more to it than just missing the "hide()" statement :). It does work as advertised. It's hard to say what is happening without seeing the rest of your code, but I'm guessing that you are hiding it and then re-showing it immediately again. Have you tried putting breakpoints in to test?

i already edited the thread with the rest of the code, if that helps

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.