-
Notifications
You must be signed in to change notification settings - Fork 1
How the Music Controller & Script work
DuncanSzabaga edited this page Nov 18, 2025
·
4 revisions
The music controller and script are designed for the following purposes
- Play music on game start
- Switch from an initial track to a loop track when a song ends
- Switch from the current song to the new song whenever the player moves to a screen with a new song
- Allow for easy modification when a new song is added to the game
Let's say for this example we want to add a song to the Store room
- In GameMaker, view the Asset Browser on the right side of the screen and, on the Sounds folder, right-click and select Create > Sound.
- A Workspace should be opened up for you to adjust the sound you want to add. Rename the sound to whatever you would like, for this example we'll rename it to "store_start".
- Select the three dots next to the name of the sound we created and navigate to wherever the audio file you're trying to add is.
- The inspector on the left will update to show the track you added. You can change any of the settings if you'd like, but they can all usually be left default besides the volume.
- In the Scripts folder of the Asset Browser navigate to MusicManager and open it.
- Locate the existing "struct_set" items at the bottom of the script.
- Copy the format of the existing "struct_set" items, but change it to match the room and the song you've added.
Your song has now been added to the game and placed within a room. Run the application and navigate to the room you've set it to to test it.
This script creates a global struct called "bgm" with the following variables
- priority: Priority of the music, only matters for resource culling.
- fadeout_ms: How long it takes a song to fade out in milliseconds.
- fadein_ms: How long it takes a song to fade in in milliseconds.
- tracks: A struct that stores which tracks are associated with each room. If a room is not added to the struct then a song change doesn't occur.
- song: The song that plays in the room.
- loop_start: The number of seconds into the song the it should be at after looping.
- loop_end: The number of seconds into the song where it should loop when reached.
- playing: The sound id for the currently playing bgm, manipulated by the controller.
- track_index: Stores the id of the playing track.
- pending_index: Stores the id of the track that is queued to play next.
Here is how the Alarm 0 Event operates after it gets triggered
- Check if there is a song queued in the pending_index.
- If a song is currently playing, stop the current song.
- The variable _track becomes the struct information for the pending room.
- playing gets assigned to the start track with its relevant extra information, starting off muted.
- The loop start and ending positions are set for the current track.
- The gain of the playing track is increased to the music_volume value for the length of fadein_ms.
- track_index is updated to the track that was in the queue.
- pending_index is updated to no longer hold a track.
This gets called when a song is switched.
Here is how the Room Start Event operates after it gets triggered
- The variable _roomname is equal to the name of the room.
- The variable _expected is assigned to either the track_index or the pending_index based on if the pending_index is undefined or not, respectively.
- If the room switched to is defined in the tracks struct and the room name does not equal the expected value, continue forward.
- The current room is queued into the pending_index.
- If a song is not currently playing, trigger the alarm.
- If a song is currently playing, begin the fade out of the current song and trigger the alarm.
Triggers on room switch, only really matters when a room has a different song than the song currently playing.
Wiki
User Stories
Design
Requirements
Architecture
Considerations & Issues
Documentation
- How to Add a Card to the Game
- How the Music Controller & Script work
- Card Paging & Search System (CardManager)
- How to Spawn Cards in a Room
- How the Chessboard works
- How to Add a New Board Color
- How to use Alert System
- Chess Logic
- Cheat Mode
- Timer
- How the new card system works
- How the NEW Chessboard works