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.