The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

I'm making a mission system where the player clicks on a mission button that initiates a timer, that timer counts down and completes the mission.

When the mission is completed, the button is repopulated with a new mission that has a new mission time length.

I have a timer node set up that ideally I just reuse by reassigning it a new setwait_time() and two if statements in the button to determine what the button does based on if the mission is complete or not.

Heres my code:

extends Control
#Boolean to stop _ready from resetting missions
var first = false
#Boolean for resetting _on_button_press
var complete = false
#randomize ID
var id = -1
#node variables.
onready var button = get_node("Panel/Button")
onready var label = get_node("Panel/Label")
onready var missiontimer = get_node("missiontimer")

## DICTIONARIES START HERE##
var a_msn = {
    title = "Test Mission A",
    msn_length = 3
}

var b_msn = {
    title = "Test Mission B",
    msn_length = 5
}

var c_msn = {
    title = "Test Mission C",
    msn_length = 7
}
## ARRAYS START HERE ##
var test_array_a = [a_msn, b_msn, c_msn]

func _randomize_mission():
    randomize()
    return randi()%3

func _pop_msn():
    id = _randomize_mission()
    label.set_text(test_array_a[id].title)
    missiontimer.set_one_shot(true)
    missiontimer.set_wait_time(test_array_a[id].msn_length)
    #missiontimer.set_active(true)

func _ready():
    # populate missions for first time.
    if first == false:
        _pop_msn()
        first = true


#on press of button, find mission's length and set it to timer's length -> run timer.
func _on_Button_pressed():
    if complete == true:
        #reward window
        get_node("Panel/Button/WindowDialog").show()
        button.set_disabled(true)
        _pop_msn()
        button.set_text("Mission Start")
        ##***note: put this disable flag in rewards popup later***##
        button.set_disabled(false)
        complete = false


    elif complete == false:
        missiontimer.start()
        button.set_disabled(true)
        print(complete)
        var time = missiontimer.get_time_left()
        print(time)
        var active = missiontimer.is_active()
        print(active)

func _on_missiontimer_timeout():
    button.set_text("complete")
    button.set_disabled(false)
    complete = true

What happens is that the mission works fine the first time, allows me to hit the the button to complete and repopulate it, but when I click 'mission start' for the second time, the timer never complete or possibly never starts and therefore never calls
onmissiontimer_timeout() again and I can not figure out why.

in Engine by (12 points)

I reconstructed your scene based on your code and it appears to work.

Control
- missiontimer (connected _on_missiontimer_timeout)
- Panel
-- Label
-- Button (connected _on_Button_pressed)

The only change to script, i commented out get_node("Panel/Button/WindowDialog").show()
Because i don't know what WindowDialog contains or if it has its own script.
It may be the cause of problem.

I don't know what you have in your scene beyond this, but stripped to the bare minimum it works for me, so the problem probably lies somewhere outside of that.

The confusing issue is the is nothing outside of this. I have it stripped to the bare minimum as well.

Here is my scene, just to see that its set up exactly as you have done it:
scene tree

The window dialog has a empty starter script that has no errors in and isn't called by anything, its just a place holder. I commented it out just as you did and ran the game to see if it functions and I still run into the same issue.

initial load up:
enter image description here
clicked and waiting for completion:
enter image description here
Completed, clickable to repopulate:
enter image description here
New mission populated, ready to click Start Mission
enter image description here

Mission Start clicked, button deactivated, timer never runs out, button never becomes complete after this:
enter image description here

so just to clarify, you did in fact get the button to reach 'complete' a second time, using my code?

Hey, so I can confirm. Your code works fine for me too. Maybe post a minimum project to test.

Yes, got to 'complete' a second time. (I tested up to 8 times with no issue.)

After some trial and error, I recreated my entire code slowly from scratch in a new project and the problem ceased to exist. My code is identical in each, so it must be some strange or obscure user error of my own fault. (something checked in the gui? Or something leftover from a deleted node??)

Thank you for showing me that it does work, I was sitting there for days trying to figure out what bizarre logic error I was making.

Please log in or register to answer this question.

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 Frequently asked questions and 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 [email protected] with your username.