I have a time variable with a value that can either be FUTURE or PAST and I have a function that changes the value from FUTURE to PAST or PAST to FUTURE, I want that function to get called whenever I press a button with Input.isactionjustpressed("changetime") but when I do the function gets called twice which returns the time variable to it's original value. Even if I do that in _input function it still get's called twice.
extends Node2D
func _ready():
pass
func _process(delta):
update_players()
func change_time(time : int = -100):
if time != -100:
Globals.time = time
if Globals.time == Globals.FUTURE:
Globals.time = Globals.PAST
elif Globals.time == Globals.PAST:
Globals.time = Globals.FUTURE
func update_players():
if Globals.time == Globals.FUTURE:
Globals.player_future.enable_player()
Globals.player_past.disable_player()
elif Globals.time == Globals.PAST:
Globals.player_past.enable_player()
Globals.player_future.disable_player()
func _input(event):
if Input.is_action_just_pressed("change_time"):
change_time()
print("time changed")