Boolean varaible will go back to it's orignal value despite being changed

Godot Version

4.3

Question

This code is isloated from the project and it still functions the same way as it did in the project.

The focus_level variable is continually being depleted and I want to pause it from being depleted.
I’m trying to pause the deplete_focus() function from getting called in physics_process(), I have a boolean variable pause_focus_depletion that gets set to true which should prevent it from being called.

The Q key input is for sake of example, in the project the function get’s called externally.

extends Node
 

var pause_focus_depletion = false

var focus_level = 100.0

func _physics_process(delta: float) -> void:
	if pause_focus_depletion == false:
		deplete_focus()
		print(focus_level)

	if Input.is_physical_key_pressed(KEY_Q):
		pause_depletion()

func deplete_focus():
	focus_level = move_toward(focus_level, 0.0, .0005)

func pause_depletion():
	pause_focus_depletion = true
	print('paused')

When you press Q it does call the function evidenced by the output


But it deplete_focus() keeps getting called

If you step into the function the value does get set to true

But when you continue it get’s set back

I realize in some way I’m truely breaking the follow of things but I have no idea how. I’m guessing there’s a better way to handle this so please fire away with what I’m doing wrong.

Do you have multiple instances of this node in the scene or do you create instances in every frame?

Can you double check it’s only one object by attaching get_instance_id() to the print statements?

I think the example here is incomplete; there’s obviously more going on but one method that may help is to create a setter/getter for the boolean property and stick a breakpoint in the code so you can see what’s changing its value.

There did end up being another instance.

This was actually in a global script so I assumed it wouldn’t be possible for there to be another one, but at some point it got attachted to a node which was the second instance.

Thanks for the help!