How do you make a key trigger subsequently play a specific note?

TheDoldrumer
TheDoldrumer Member Posts: 7 Sine
edited June 29 in Scripting Workshop

I'm not the best with KSP, so I'm wondering how to script a key trigger that, when pressed and held, plays a specific note on the keyboard, without having to play the note itself on the keyboard. I'm looking for this to account for the note on and note off information and while the note is held.

I know this may sound simple, but I must be missing something.

Essentially all I'm looking to do is have my $KEY_SWITCH also trigger note 22.

The script as followed:

on init	

declare $count
	declare $fade_out
	declare ui_knob $fade_time(10000,1000000,100000)
	set_text($fade_time,"Length")
	make_persistent($fade_time)
	move_control($fade_time,1,1)

  declare const $KEY_SWITCH := 2
	set_key_color(12,$KEY_COLOR_RED)

end on
on note
	
	if ($EVENT_NOTE=$KEY_SWITCH)
	fade_out($ALL_EVENTS,$fade_time,0)
	$fade_out := 0
	end if

end on

Best Answer

  • TheDoldrumer
    TheDoldrumer Member Posts: 7 Sine
    Answer ✓

    I realized the event duration variable had to be -1 for the the note off to be sent for the key trigger, but this worked, thanks!


    on note
    
    if ($EVENT_NOTE=$KEY_SWITCH)
    play_note(22,0,0,-1)
    end if
    
    end on
    


Answers

  • EvilDragon
    EvilDragon CroatiaModerator Posts: 672 mod

    play_note() is what you're looking for.

  • TheDoldrumer
    TheDoldrumer Member Posts: 7 Sine
    Answer ✓

    I realized the event duration variable had to be -1 for the the note off to be sent for the key trigger, but this worked, thanks!


    on note
    
    if ($EVENT_NOTE=$KEY_SWITCH)
    play_note(22,0,0,-1)
    end if
    
    end on
    


Back To Top