Hello whinter,
You can achieve this functionality where a sound plays when you press a key on the keyboard and stops when you release it using the logic demonstrated in the provided image. Additionally, here’s an example you can view and test:
www.gamemaker3d.com/player?pid=01665538
Explanation:
1. Loop Execution:
The logic continuously checks for key presses and changes the state of the variable play_music.
2. Key Press Handling:
• When a key (e.g., 1) is pressed, the program checks the value of the variable play_music.
• If play_music is 0 (indicating the sound is not currently playing), the following occurs:
• The sound (sound1) plays.
• A message is optionally displayed (for testing or debugging purposes).
• The variable play_music is set to 1 to indicate that the sound is now playing.
3. Key Release Handling:
• When the key is released, the program toggles back:
• The sound (sound1) stops by setting its volume to 0.
• The variable play_music is reset to 0.
This setup ensures the sound toggles on and off based on the key press/release state.
You can test this in action with the example provided in the link above. Let us know if you need further assistance!
Regards,
Cyberix3D team