How do I detect if a var has reached a certain number?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By VirtualTeddy

Okay so I have a

var current_dia_id = 0

Then I have it where once it’s been interacted with, it will up the number.

func _input(event):
if not d_active:
	return
if event.is_action_pressed("ui_accept"):
	next_script()
	
func next_script():
    current_dia_id += 1

Now here let me lay out the piece of code I’m stuck on.

The first part of the script for the length of dialogue, it just detects if it has reached the end and then makes it invisible. That part I know works. But the part underneath it is the part that’s kicking my butt. I am trying to make it detect when the current_dia_id becomes a certain number, so that when it is that number it plays an animation. I don’t know if I have it placed in a wrong position or what. Can anyone help?

func next_script():
current_dia_id += 1

if current_dia_id >= len(dialogue):
	$Timer.start()
	$NinePatchRect.visible = false
	return
	
	
if current_dia_id == [0]:
	$AnimationPlayer.play("textpop")
if current_dia_id == [1]:
	$AnimationPlayer.play("textpop")
if current_dia_id == [2]:
	$AnimationPlayer.play("textpop")
	
$NinePatchRect/Name.text = dialogue[current_dia_id]['name']
$NinePatchRect/Text.text = dialogue[current_dia_id]['text']
:bust_in_silhouette: Reply From: jgodfrey

The most obvious problem here is in how you’ve written the comparison value in the 3 lines similar to this:

if current_dia_id == [0]:

That’s not comparing the integer value contained in the current_dia_id variable to the integer value of 0. Instead, that’s attempting to compare the value of the variable to an array that contains the element 0. I expect that’s giving you an error, isn’t it?

Instead, you want this:

if current_dia_id == 0:

(and, the same for the other similar lines).

I-
Wow it was simpler than I thought.
Thank you for telling me. I’m new to this so I get mixed up on the small details like that <3

VirtualTeddy | 2023-01-31 19:59