My custom function isn't working

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

This is an excerpt of code I have for a game I’ve been working on:

var scene_number = 0
func _on_Area2D_input_event(viewport, event, shape_idx):
    if event is InputEventMouseButton:
	     scene_number += 1

func stop_music():
     if scene_number == 1:

The scene number updates when I click on a sprite and I’ve confirmed this with a print function, so how come it won’t print out “hello” when the scene_number == 1 (after one mouse click)

In addition to the answers you got, the scene_number var will also change from being 1 as two events actions happen during InputEventMouseButton

  1. MouseButton pressed down
  2. MouseButton press released

So if your stop_music function is being called maybe try

#if greater than or equal to
if scene_number >= 1: 

Wakatta | 2021-09-21 01:06

:bust_in_silhouette: Reply From: stormreaver

Nowhere in your code snippet does stop_music() get called.

:bust_in_silhouette: Reply From: skysphr

That would depend on when the stop_music() function is being called. Try to print something before the if statement, to see if the function is fired at the appropriate time.