r/godot•
weavileisgodlike

Struggling with midi piano inputs

help me

I want to make a program in Godot for pressing the right notes on a piano for my sister. When I press a note the enemy disappears but pressing and releasing both count as a press, so if I hold the note and a different enemy comes on screen and I let go it registers as a press. How would I make It so that the second press(releasing) doesn't activate.

sorry if my code sucks

this is the code I started

extends Node2D

@/onready var H = $H
@/onready var C_anim = $AnimatedSprite2D
@/onready var global = preload("res://scripts/Global.gd")

var sensor_yo = 0

var wrong= false

signal franny

func _ready():

C\_anim.play("note\_spawn") #spawning animation  
print("before")  
await get\_tree().create\_timer(3).timeout #timer that waits for sensor to change in turn allowing you to attack  
\#also lets us know that the spawning animation is going/ enemies are invulnerable   
  
OS.open\_midi\_inputs()  
print(OS.get\_connected\_midi\_inputs())  
OS.get\_connected\_midi\_inputs()  
  
  
print("after/spawned")  
sensor\_yo = 1 #turns sensor to 1 allowing us to attack  
C\_anim.play("note\_Idle")   
  
await get\_tree().create\_timer(5.5).timeout  
\_attack() #the attack in ready  
  
  
  
  
  


  
  

func _input(input_event):
if input_event is InputEventMIDI:
_print_midi_info(input_event)

func _print_midi_info(midi_event):
print(midi_event)

print("Pitch", midi\_event.pitch)  
  
  
\#if midi\_event.pitch == 64 and sensor\_yo == 0:  
	\#print("nothing happening/animation")  
	  
	  
  
  
  
  
  
	  
  
if midi\_event.pitch == 64 and sensor\_yo == 1:  
	  
	  
	\#animation plays  
	print("deth animation")  
	C\_anim.play("note\_deading")  
	sensor\_yo = 2  
	await get\_tree().create\_timer(1.5).timeout  
	print("deet")  
	queue\_free()  
		  
elif sensor\_yo == 1 and midi\_event.pitch > 64:#attack will instantly go off in you pick a note greater than 64  

	\_attack() # attack alresy goes off so no minus hp here  
	sensor\_yo = 3  
	  
elif sensor\_yo == 1 and midi\_event.pitch < 64:#attack will instantly go off in you pick a note less than 64  
	\_attack()   
	sensor\_yo = 3  
	  
	if midi\_event.pitch == 64 and sensor\_yo == 2:  
		\#we can make the points come after it dies   

if midi_event.pitch == 64 and sensor_yo == 3:
midi_event.pitch == false
func _process(delta):
pass

func _attack():

	await get\_tree().create\_timer(0.5).timeout #timer before attack for being wrong  
	  
	Global.Player\_hp -= 1  
	\#var Player\_hp - 1  
	print(Global.Player\_hp)  
	C\_anim.play("note\_wrong")  
	  
	await get\_tree().create\_timer(0.6).timeout  
	C\_anim.play("note\_deading")  
	  
	await get\_tree().create\_timer(1).timeout  
	print("deet")  
	queue\_free()  
	  
	  
	  

Posted Apr 8, 2025, 9:14 PM UTC

31
Loading comments…