Script wont work for variable

For my code, it works for if quest is = to 0, but when it’s 1 it wont run anything. the value is set to one i made sure through the console so there has to be some other problem.

extends CollisionObject3D
class_name Interactable

@export var prompt = "Press E to Interact"
@onready var text = $"../dialogue"
var quest = Global.quest

func interact(body):
	print("Interacted")
	if quest == 0:
		if Global.drink == false:
			Global.interactable = false
			print("interacted")
			text.text = "Hello, friend!"
			await get_tree().create_timer(3).timeout
			text.text = "It's me, your best friend."
			await get_tree().create_timer(3).timeout
			text.text = "Can you get me a drink?"
			await get_tree().create_timer(3).timeout
			text.text = ""
			Global.drink = true
			Global.interactable = true
		elif Global.drink and Global.pickupdrink == false:
			Global.interactable = false
			text.text = "Go get me a drink!"
			await get_tree().create_timer(3).timeout
			text.text = ""
			Global.interactable = true
			
	elif Global.quest == 1:
		print("Comeon")
		if Global.pickupdrink:
			Global.interactable = false
			text.text = "Mmmm, tasty!"
			await get_tree().create_timer(3).timeout
			text.text = "Now, get me the soup!"
			await get_tree().create_timer(3).timeout
			text.text = ""
			Global.soup = true
			Global.drink =false
			Global.pickupdrink = false
			Global.interactable = true
		elif Global.soup:
			text.text = "Don't make me hit you again, you FUCK."
			await get_tree().create_timer(3).timeout
			text.text = ""

the first if checks for “quest” and the second if checks for “Global.quest”. Are you sure you are checking the correct variable?

Even after fixing it, it’s still the same problem.

What exactly did you fix and can you print out the variable that you are checking before the if statement?

Fixed it! Turns out I shouldn’t use a local variable for global variables.

1 Like