• All, Gmail is currently rejecting messages from my host. I have a ticket in process, but it may take some time to resolve. Until further notice, do NOT use Gmail for your accounts. You will be unable to receive confirmations and two factor messages to login.

BGM Select Menu Inside New Extra Options Menu in Menu/Title Screen

maxman

Well-known member
By not derailing this musicoverlap topic, I decided to create a new thread asking how I could get started with adding a new menu as extra option like SOR2X. A music switch according to the playlist version being chosen. For example, in Tekken 2 and 3, you go to options menu > game option and then you go to BGM select and switch from arrange to original/arcade. That's because I want to switch music in that menu so that I could play with red, blue, and green versions in certain music playlists. A step-by-step process is welcome.

EDIT: For instance, I want to use the songs from both the main music folder and its subfolders. I would like to have 3 options of red, green, and blue for selecting music you go to arcade mode with. When you choose "Red" in the extra options mode, the playlist will play all the songs from the red version in game mode.
 
Last edited:
Solution
By not derailing this musicoverlap topic, I decided to create a new thread asking how I could get started with adding a new menu as extra option like SOR2X. A music switch according to the playlist version being chosen. For example, in Tekken 2 and 3, you go to options menu > game option and then you go to BGM select and switch from arrange to original/arcade. That's because I want to switch music in that menu so that I could play with red, blue, and green versions in certain music playlists. A step-by-step process is welcome.

EDIT: For instance, I want to use the songs from both the main music folder and its subfolders. I would like to have 3 options of red, green, and blue for selecting music you go to arcade mode with...
By not derailing this musicoverlap topic, I decided to create a new thread asking how I could get started with adding a new menu as extra option like SOR2X. A music switch according to the playlist version being chosen. For example, in Tekken 2 and 3, you go to options menu > game option and then you go to BGM select and switch from arrange to original/arcade. That's because I want to switch music in that menu so that I could play with red, blue, and green versions in certain music playlists. A step-by-step process is welcome.

EDIT: For instance, I want to use the songs from both the main music folder and its subfolders. I would like to have 3 options of red, green, and blue for selecting music you go to arcade mode with. When you choose "Red" in the extra options mode, the playlist will play all the songs from the red version in game mode.
@maxman Once the previous script already does most of the job, all we need to do is a small menu to switch between some variables, and then apply these variables in the music script.
Here goes the menu already applied. Below you can see the changes, I coded a menu as an example inside the how to play option with a blank gif file.

Updated.c
C:
#import "data/scripts/musics.c"

void main()
{//Start all tasks
    
    if(openborvariant("in_titlescreen")){

        //FLAG USED TO INDICATE IF THE LEVEL MUSIC IS STOPPED TO THE "MUSICSTAGE.C" FUNCTIONS
        if(getglobalvar("musicStopped") != 1){setglobalvar("musicStopped", 1);}
        if(getglobalvar("mStyle") == NULL()){setglobalvar("mStyle", 0);}
    }

    if(openborvariant("in_level")){
        
        //RESTART MUSICS EVERYTIME THE SOUND MENU IS ACCESSED
        //USED BECAUSE SCRIPTED MUSICS DON'T RESTARTS AUTOMATICALLY IF THE PLAYER DISABLE/ENABLE IT IN THE SOUND MENU
        if(openborvariant("pause") && openborvariant("in_sound_options")){
            if(getglobalvar("soundMenu") == NULL()){setglobalvar("soundMenu", 1);}
        }
        else
        if(!openborvariant("pause")){
            if(getglobalvar("soundMenu") != NULL()){musicReplay();setglobalvar("soundMenu", NULL());}
        }
    }

    if(openborvariant("current_scene") == "data/scenes/howto.txt"){
        musicMenu();
    }
}

void musicMenu()
{//Draw a Menu in/out game

    //DRAW MENU
    if(openborvariant("current_scene") == "data/scenes/howto.txt"){
        void str;
        float hRes    = openborvariant("hresolution");
        int mStyle    = getglobalvar("mStyle");
        int align;
        int xDif    = 10;                //DIFFERENCE BETWEEN THE FIRST AND SECOND COLUMNS
        int xPos1    = (hRes/2)-xDif;    //BASE X POSITION, FIRST COLUMN (HIGHLIGHTED OPTIONS NAME)
        int xPos2    = (hRes/2)+xDif;    //BASE X POSITION, SECOND COLUMN (HIGHLIGHTED OPTIONS CHANGE)
        int yPos    = 60;                //BASE Y POSITION FOR ALL MENU CONTENT, USE THIS TO MOVE ALL OPTIONS TOGETHER
        int font    = 0;                //ALL FONTS BELOW CHANGES FROM 0 TO 1 IF THE OPTION IS HIGHLIGHTED
        int layer    = 1000000003;
        
        //OPTION TITLE
        str = "Music_Style:";align = xPos1-strwidth(str, font);
        drawstring(align, yPos, font, str, layer);

        //OPTION NAME
        if(mStyle == 0){str = "Original";}
        if(mStyle == 1){str = "Arcade";}
        drawstring(xPos2, yPos, font, str, layer);
    }
}

Keyall.c
C:
void main()
{//Global keyall scripts, detects player index
    int player = getlocalvar("player");
    
    menuMusic(player);
}

void menuMusic(int player)
{//Change music style
    int moveright    = playerkeys(player, 1, "moveright");
    int moveleft    = playerkeys(player, 1, "moveleft");
    int mStyle        = getglobalvar("mStyle");
    int volume        = openborvariant("effectvol");
    int speed        = 100;
    int loop        = 0;
    int min            = 0;
    int max            = 1;
    int add            = 1;
    
    if(openborvariant("current_scene") == "data/scenes/howto.txt"){
        if(moveright){
            playsample(openborconstant("SAMPLE_BEEP"), 0, volume, volume, speed, loop);
            if(mStyle >= min && mStyle < max){setglobalvar("mStyle", mStyle+add);}
            if(mStyle == max){setglobalvar("mStyle", min);}
        }
        if(moveleft){
            playsample(openborconstant("SAMPLE_BEEP"), 0, volume, volume, speed, loop);
            if(mStyle > min && mStyle <= max){setglobalvar("mStyle", mStyle-add);}
            if(mStyle == min){setglobalvar("mStyle", max);}
        }
    }
}

Musics.c
C:
void musicStage()
{//Play music in each stage
    void branch    = openborvariant("current_branch");
    void music;
    void folder;
    int mStyle    = getglobalvar("mStyle");

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "subfolder";}
    
    //LEVEL 1
    if(branch == "Level_1"){music = "01.ogg";    musicPlay(music, folder, 1);}

    //LEVEL 2
    if(branch == "Level_2"){music = "02.ogg";    musicPlay(music, folder, 1);}

    //LEVELS 3-4
    //HERE IS THE CORE OF THE MUSIC CONTINUATION LOGIC, YOU MUST FOLLOW THIS SAME STRUCTURE
    if(branch == "Level_3"){
        music = "03.ogg";
        musicPlay(music, folder, 1);
        setglobalvar("musicStopped", NULL()); //CLEAR THE VARIABLE TO BE USED IN THE NEXT LEVEL
    }

    //THE VARIABLE "MUSICSTOPPED" WAS PREVIOUSLY SET TO 1 BY DEFAULT IN THE UPDATED.C AT THE TITLE SCREEN
    //IF THIS LEVEL WAS REACHED AFTER BEATING THE PREVIOUS LEVEL, IT MEANS THAT THE MUSIC IS ALREADY PLAYING AND NO NEED TO REPLAY
    //IF THIS LEVEL WAS REACHED DIRECTLY THROUGH LOADING OR LEVEL SELECTION, THE VARIABLE WAS NOT CLEARED AND THE MUSIC MUST BE REPLAYED
    if(branch == "Level_4"){
        if(getglobalvar("musicStopped") != NULL()){
            music = "03.ogg";
            musicPlay(music, folder, 1);
            setglobalvar("musicStopped", NULL());
        }
    }

    //LEVEL 5
    if(branch == "Level_5"){music = "05.ogg";    musicPlay(music, folder, 1);}
}

void musicPlay(void music, void mStyle, int loop, int offset)
{//Play defined music, global usage function
    void folder;
    
    //GET CURRENT MUSIC STYLE
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}

    //SET LOOP TO ZERO IF NULL
    if(loop == NULL()){loop = 0;}

    //SET OFFSET TO ZERO IF NULL
    if(offset == NULL()){offset = 0;}

    //SAVE THE CURRENT MUSIC INTO A VARIABLE
    setglobalvar("musicPlaying", music);

    //PLAY MUSIC
    fademusic(0);
    playmusic(folder+music, loop, offset);
}

void musicReplay()
{//Replay the current music if the style is changed in-game
    void music = getglobalvar("musicPlaying");
    
    if(music != NULL()){
        if(openborvariant("in_level")){musicPlay(music, "root", 1);}
    }
}

Howto.txt, repeated the gif scene many times because the hotwto duration is based on the gif duration.
Code:
animation    data/scenes/howto.gif 0 0
animation    data/scenes/howto.gif 0 0
animation    data/scenes/howto.gif 0 0
animation    data/scenes/howto.gif 0 0
animation    data/scenes/howto.gif 0 0
animation    data/scenes/howto.gif 0 0
animation    data/scenes/howto.gif 0 0
animation    data/scenes/howto.gif 0 0

 
Solution
Thanks for the scripts, Kratus. However, I encountered this issue I made my edits. Here's the log.

Code:
Total Ram: 4171603968 Bytes
 Free Ram: 935510016 Bytes
 Used Ram: 6303744 Bytes

debug:nativeWidth, nativeHeight, bpp, Hz  1366, 768, 24, 60
OpenBoR v3.0 Build 6391, Compile Date: Apr  8 2020

Game Selected: ./Paks/My Mod.pak

FileCaching System Init......    Disabled
Initializing video............
Reading video settings from 'data/video.txt'.
Initialized video.............    480x272 (Mode: 1)

Loading menu.txt.............    Done!
Loading fonts................    1 2 3 4 Done!
Timer init...................    Done!
Initialize Sound..............   
Loading sprites..............    Done!
Loading level order..........    Done!
Loading model constants......    Done!
Loading script settings......    Done!
Loading scripts..............   

Script error: data/scripts/music.c, line 17: Invalid external declaration 'if' (in production 'external_decl')

    if(set == 0){
    ^

Script error: failed to import 'data/scripts/music.c': parsing failed

********** An Error Occurred **********
*            Shutting Down            *

Can't compile script 'update'
Total Ram: 4171603968 Bytes
 Free Ram: 696098816 Bytes
 Used Ram: 31625216 Bytes

Release level data...........
Done!

Release graphics data........    Done!
Release game data............


Release game data............    Done!
Release timer................    Done!
Release input hardware.......    Done!
Release sound system.........    Done!
Release FileCaching System...    Done!

**************** Done *****************

Can't compile script 'update'

Here's my music.c for playing music. It mentions about the set 0 (first game mode), but I don't understand how/why it causes the problem here. Is there anything I did wrong?

C:
void musicStage()
{//Play music in each stage
 //musicStopped global variable usage: 1 = Stage music is Stopped / NULL() = Stage music is Playing
    void branch    = openborvariant("current_branch");
    void music;
    void folder;
    int stopMusic;
    int set    = openborvariant("current_set");
    int mStyle = getglobalvar("mStyle");

   
    if(mStyle == 0){folder = "root";}
    if(mStyle == 1) folder = "subfolder";}
    //if(mStyle == 2) folder = "Blue";}
   
   
    if(set == 0){

        // STAGE 1
        //if(branch == "Stage1"){music = "miami.bor";    musicPlay(music, "root", 1, 628562.9198609781);}
        if(branch == "Stage1"){music = "miami.bor";    musicPlay(music, folder, 1, 628562.92);}

        // STAGE 2-1 AND LEVEL 2-2
        //HERE IS THE CORE OF THE MUSIC CONTINUATION LOGIC, YOU MUST FOLLOW THIS SAME STRUCTURE
        //THE "STOPMUSIC" OPTION IS "NO"?? ALL LEVELS BELOW WILL USE THE SAME MUSIC

        // STAGE 2-1
        if(branch == "Stage2-1"){
            music = "italy.bor";
            musicPlay(music, folder, 1);
            setglobalvar("musicStopped", NULL()); //CLEAR THE VARIABLE TO BE USED IN THE NEXT LEVEL
        }


        //THE VARIABLE "MUSICSTOPPED" WAS PREVIOUSLY SET TO 1 BY DEFAULT IN THE UPDATED.C AT THE TITLE SCREEN
        //IF THIS LEVEL WAS REACHED AFTER BEATING THE PREVIOUS LEVEL, IT MEANS THAT THE MUSIC IS ALREADY PLAYING AND NO NEED TO REPLAY
        //IF THIS LEVEL WAS REACHED DIRECTLY THROUGH LOADING OR LEVEL SELECTION, THE VARIABLE WAS NOT CLEARED AND THE MUSIC MUST BE REPLAYED

        // STAGE 2-2
        if(branch == "Stage2-2"){
            if(getglobalvar("musicStopped") != NULL()){
                music = "italy.bor";
                musicPlay(music, folder, 1);
                setglobalvar("musicStopped", NULL());
            }
        }

        // STAGE 3-1
        if(branch == "Stage3-1"){music = "rave1.bor";    musicPlay(music, folder, 1);}
        // STAGE 3-2
        if(branch == "Stage3-2"){music = "rave2.bor";    musicPlay(music, folder, 1);}
        // STAGEL 3-3
        if(branch == "Stage3-3"){music = "rave1.bor";    musicPlay(music, folder, 1);}

        // STAGE 4-1
        if(branch == "Stage4-1"){
            music = "egypt2.bor";
            musicPlay(music, folder, 1);
            setglobalvar("musicStopped", NULL()); //CLEAR THE VARIABLE TO BE USED IN THE NEXT LEVEL

        }

        // STAGE 4-2
        if(branch == "Stage4-2"){
            if(getglobalvar("musicStopped") != NULL()){
                music = "egypt2.bor";
                musicPlay(music, folder, 1);
                setglobalvar("musicStopped", NULL());
            }
        }


        // STAGE 5-1
        if(branch == "Stage5-1"){
            music = "china.bor";
            musicPlay(music, folder, 1);
            setglobalvar("musicStopped", NULL()); //CLEAR THE VARIABLE TO BE USED IN THE NEXT LEVEL

        }

        // STAGE 5-2
        if(branch == "Stage5-2"){
            if(getglobalvar("musicStopped") != NULL()){
                music = "china.bor";
                musicPlay(music, folder, 1);
                setglobalvar("musicStopped", NULL());
            }
        }

        // STAGE 6-1
        if(branch == "Stage6-1"){music = "jungle1.bor";    musicPlay(music, "root", 1);}

        // STAGE 6-2
        if(branch == "Stage6-2"){music = "jungle2.bor";    musicPlay(music, "root", 1);}

        // STAGE 6-3
        if(branch == "Stage6-3"){music = "rush.bor";    musicPlay(music, "root", 1);}
    }
   

    if(set == 2){
        // LEVEL 0-1
        if(branch == "Test0-1"){music = "rave1.bor";    musicPlay(music, "root", 1);}
        // LEVEL 0-2
        if(branch == "Test0-2"){music = "rave2.bor";    musicPlay(music, "root", 1);}
        // LEVEL 0-3
        if(branch == "Test0-3"){music = "rave1.bor";    musicPlay(music, "root", 1);}

        // LEVEL 1-1 AND LEVEL 1-2
        //HERE IS THE CORE OF THE MUSIC CONTINUATION LOGIC, YOU MUST FOLLOW THIS SAME STRUCTURE
        //THE "STOPMUSIC" OPTION IS "NO"?? ALL LEVELS BELOW WILL USE THE SAME MUSIC
        if(branch == "Test1-1"){
            music = "italy.bor";
            musicPlay(music, "root", 1);
            setglobalvar("musicStopped", NULL()); //CLEAR THE VARIABLE TO BE USED IN THE NEXT LEVEL
        }


        //THE VARIABLE "MUSICSTOPPED" WAS PREVIOUSLY SET TO 1 BY DEFAULT IN THE UPDATED.C AT THE TITLE SCREEN
        //IF THIS LEVEL WAS REACHED AFTER BEATING THE PREVIOUS LEVEL, IT MEANS THAT THE MUSIC IS ALREADY PLAYING AND NO NEED TO REPLAY
        //IF THIS LEVEL WAS REACHED DIRECTLY THROUGH LOADING OR LEVEL SELECTION, THE VARIABLE WAS NOT CLEARED AND THE MUSIC MUST BE REPLAYED
        // LEVEL 1-2
        if(branch == "Test1-2"){
            if(getglobalvar("musicStopped") != NULL()){
                music = "italy.bor";
                musicPlay(music, "root", 1);
                setglobalvar("musicStopped", NULL());
            }
        }

        // LEVEL 1-3
        if(branch == "Test1-3"){music = "versus.bor";    musicPlay(music, "root", 1);}
    }

}

void musicPlay(void music, void mStyle, int loop, int offset)
{//Play defined music, global usage function
    void folder;
   
    //GET CURRENT MUSIC STYLE
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}

    //SET LOOP TO ZERO IF NULL
    if(loop == NULL()){loop = 0;}

    //SET OFFSET TO ZERO IF NULL
    if(offset == NULL()){offset = 0;}

    //CHECK IF THE MUSIC WAS PLAYED BY USING GAME SETTINGS, SAVE ONLY IF WAS PLAYED "IN-LEVEL"
    setglobalvar("musicPlaying", music);

    //RESET THE FLAG USED FOR THE GAME SETTINGS CHECK
    setglobalvar("bgmPlay", NULL());

    //PLAY MUSIC
    fademusic(0);
    playmusic(folder+music, loop, offset);
}

void musicReplay()
{//Replay the current music if the style is changed in-game
    void music = getglobalvar("musicPlaying");
   
    if(music != NULL()){
        if(openborvariant("in_level")){musicPlay(music, "root", 1);}
    }
}
 
Last edited:
Thank you very much! I got it all working. And yes, I forgot to add the starting bracket. How about adding another one for another music subfolder? I want to play music from the "Blue" subfolder too.

EDIT: Oh. After changing music option from general (green) to subfolder (red) in How-to-Play mode, how about changing music to its respective subfolder after? Let's say, for example, you change it to Red there, and the music switches to the red version. Specifically, remix.bor and menu.bor will play in their respective subfolders.
 
Last edited:
How about adding another one for another music subfolder? I want to play music from the "Blue" subfolder too.
To add more subfolders, just add more options for the music style variables.

Keyall.c, add one more at "max" variable and now is 2.
C:
void menuMusic(int player)
{//Change music style
    int moveright    = playerkeys(player, 1, "moveright");
    int moveleft    = playerkeys(player, 1, "moveleft");
    int mStyle        = getglobalvar("mStyle");
    int volume        = openborvariant("effectvol");
    int speed        = 100;
    int loop        = 0;
    int min            = 0;
    int max            = 2;
    int add            = 1;
  
    if(openborvariant("current_scene") == "data/scenes/howto.txt"){
        if(moveright){
            playsample(openborconstant("SAMPLE_BEEP"), 0, volume, volume, speed, loop);
            if(mStyle >= min && mStyle < max){setglobalvar("mStyle", mStyle+add);}
            if(mStyle == max){setglobalvar("mStyle", min);}
        }
        if(moveleft){
            playsample(openborconstant("SAMPLE_BEEP"), 0, volume, volume, speed, loop);
            if(mStyle > min && mStyle <= max){setglobalvar("mStyle", mStyle-add);}
            if(mStyle == min){setglobalvar("mStyle", max);}
        }
    }
}

Musics.c, add one more "subfolder" line.
C:
void musicStage()
{//Play music in each stage
    void branch    = openborvariant("current_branch");
    void music;
    void folder;
    int mStyle    = getglobalvar("mStyle");

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "subfolder1";}
    if(mStyle == 2){folder = "subfolder2";}

Updated.c, add one more "subfolder" text.
C:
void musicMenu()
{//Draw a Menu in/out game

    //DRAW MENU
    if(openborvariant("current_scene") == "data/scenes/howto.txt"){
        void str;
        float hRes    = openborvariant("hresolution");
        int mStyle    = getglobalvar("mStyle");
        int align;
        int xDif    = 10;                //DIFFERENCE BETWEEN THE FIRST AND SECOND COLUMNS
        int xPos1    = (hRes/2)-xDif;    //BASE X POSITION, FIRST COLUMN (HIGHLIGHTED OPTIONS NAME)
        int xPos2    = (hRes/2)+xDif;    //BASE X POSITION, SECOND COLUMN (HIGHLIGHTED OPTIONS CHANGE)
        int yPos    = 60;                //BASE Y POSITION FOR ALL MENU CONTENT, USE THIS TO MOVE ALL OPTIONS TOGETHER
        int font    = 0;                //ALL FONTS BELOW CHANGES FROM 0 TO 1 IF THE OPTION IS HIGHLIGHTED
        int layer    = 1000000003;
      
        //OPTION TITLE
        str = "Music_Style:";align = xPos1-strwidth(str, font);
        drawstring(align, yPos, font, str, layer);

        //OPTION NAME
        if(mStyle == 0){str = "Original";}
        if(mStyle == 1){str = "Arcade";}
        if(mStyle == 2){str = "Custom";}
        drawstring(xPos2, yPos, font, str, layer);
    }
}

EDIT: Don't forget that you can change the subfolder's name, I put this way just to show an example.
 
EDIT: Oh. After changing music option from general (green) to subfolder (red) in How-to-Play mode, how about changing music to its respective subfolder after? Let's say, for example, you change it to Red there, and the music switches to the red version. Specifically, remix.bor and menu.bor will play in their respective subfolders.
The script will not affect native music events like menu.bor or remix.bor, only level events.
 
Should I put them in another subfolder so that they would be used for the title-menu event?
Not exactly, the engine will not look for these native musics in other folders than "data/music". However, you can use the updated.c to add more events where these scripted musics will be played, allowing you to select different folders for the menu/remix.bor too. You can see an example in the SOR2X when I play music during the "complete screen" or "game over" events.
 
@Kratus What do you think if I want to loop one specific song with its own offset from one music style? What I want is to loop with music offset. Do you think that using the global varname with its value can work without memory leak? The first line I have is the one with green version because I want to loop to its offset, but the ones in subfolders I leave them be.

C:
        if(branch == "Stage1" && mStyle == 0){music = "miami.bor";    musicPlay(music, folder, 1, 632124.53);} // For music looping purpose
        if(branch == "Stage1"){music = "miami.bor";    musicPlay(music, folder, 1);} // No need to loop songs with same name in music folders
 
@Kratus What do you think if I want to loop one specific song with its own offset from one music style? What I want is to loop with music offset. Do you think that using the global varname with its value can work without memory leak? The first line I have is the one with green version because I want to loop to its offset, but the ones in subfolders I leave them be.

C:
        if(branch == "Stage1" && mStyle == 0){music = "miami.bor";    musicPlay(music, folder, 1, 632124.53);} // For music looping purpose
        if(branch == "Stage1"){music = "miami.bor";    musicPlay(music, folder, 1);} // No need to loop songs with same name in music folders
Currently I'm using a similar loop configuration in the SORX but instead of editing the musicStage function, I'm editing the musicPlay function directly. It's more simple because I don't need to repeat lines for every branch name.

1692131838888.png

In your code it will look like this:
C:
void musicPlay(void music, void mStyle, int loop, int offset)
{//Play defined music, global usage function
    void folder;
    
    //GET CURRENT MUSIC STYLE
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}

    if(mStyle == "root"){
        if(music == "01.ogg"){offset = 123456789;}
        if(music == "02.ogg"){offset = 123456789;}
        if(music == "03.ogg"){offset = 123456789;}
        if(music == "04.ogg"){offset = 123456789;}
        if(music == "05.ogg"){offset = 123456789;}
    }

    if(mStyle == "subfolder1"){
        if(music == "01.ogg"){offset = 123456789;}
        if(music == "02.ogg"){offset = 123456789;}
        if(music == "03.ogg"){offset = 123456789;}
        if(music == "04.ogg"){offset = 123456789;}
        if(music == "05.ogg"){offset = 123456789;}
    }

    if(mStyle == "subfolder2"){
        if(music == "01.ogg"){offset = 123456789;}
        if(music == "02.ogg"){offset = 123456789;}
        if(music == "03.ogg"){offset = 123456789;}
        if(music == "04.ogg"){offset = 123456789;}
        if(music == "05.ogg"){offset = 123456789;}
    }

    //SET LOOP TO ZERO IF NULL
    if(loop == NULL()){loop = 0;}

    //SET OFFSET TO ZERO IF NULL
    if(offset == NULL()){offset = 0;}

    //SAVE THE CURRENT MUSIC INTO A VARIABLE
    setglobalvar("musicPlaying", music);

    //PLAY MUSIC
    fademusic(0);
    playmusic(folder+music, loop, offset);
}
 
Good to know! I don't have to just use this in musicStage() function. I can also add it in musicPlay() for looping which music I want. I have this one here.

C-like:
void musicStage()
{//Play music in each stage
 //musicStopped global variable usage: 1 = Stage music is Stopped / NULL() = Stage music is Playing
    void branch    = openborvariant("current_branch");
    void music;
    void folder;
    int stopMusic;
    int set    = openborvariant("current_set");
    int mStyle = getglobalvar("mStyle");

    
    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "Red";}
    if(mStyle == 2){folder = "Blue";}
    
    
    if(set == 0){

        // STAGE 1
        //if(branch == "Stage1"){music = "miami.bor";    musicPlay(music, "root", 1, 628562.9198609781);}
        //if(branch == "Stage1"){music = "miami.bor";    musicPlay(music, folder, 1, 632124.53);} // No need to loop songs with same name in music folders

        if(branch == "Stage1" && mStyle == 0){music = "miami.bor";    musicPlay(music, folder, 1, 632124.53);} // For music looping purpose
        if(branch == "Stage1"){music = "miami.bor";    musicPlay(music, folder, 1);}


        // STAGE 2-1 AND LEVEL 2-2
        //HERE IS THE CORE OF THE MUSIC CONTINUATION LOGIC, YOU MUST FOLLOW THIS SAME STRUCTURE
        //THE "STOPMUSIC" OPTION IS "NO"?? ALL LEVELS BELOW WILL USE THE SAME MUSIC

        // STAGE 2-1
        if(branch == "Stage2-1" && mStyle == 0){
            music = "italy.bor";
            musicPlay(music, folder, 1);
            setglobalvar("musicStopped", NULL()); //CLEAR THE VARIABLE TO BE USED IN THE NEXT LEVEL
        }

        // Blue and Red versions
        if(branch == "Stage2-1"){
            music = "italy.bor";
            musicPlay(music, folder, 1);
            setglobalvar("musicStopped", NULL()); //CLEAR THE VARIABLE TO BE USED IN THE NEXT LEVEL
        }


        //THE VARIABLE "MUSICSTOPPED" WAS PREVIOUSLY SET TO 1 BY DEFAULT IN THE UPDATED.C AT THE TITLE SCREEN
        //IF THIS LEVEL WAS REACHED AFTER BEATING THE PREVIOUS LEVEL, IT MEANS THAT THE MUSIC IS ALREADY PLAYING AND NO NEED TO REPLAY
        //IF THIS LEVEL WAS REACHED DIRECTLY THROUGH LOADING OR LEVEL SELECTION, THE VARIABLE WAS NOT CLEARED AND THE MUSIC MUST BE REPLAYED

        // STAGE 2-2
        if(branch == "Stage2-2" && mStyle == 0){
            if(getglobalvar("musicStopped") != NULL()){
                music = "italy.bor";
                musicPlay(music, folder, 1);
                setglobalvar("musicStopped", NULL());
            }
        }

        if(branch == "Stage2-2"){
            if(getglobalvar("musicStopped") != NULL()){
                music = "italy.bor";
                musicPlay(music, folder, 1);
                setglobalvar("musicStopped", NULL());
            }
        }

        // STAGE 3-1
        if(branch == "Stage3-1"){music = "rave1.bor";    musicPlay(music, folder, 1);}
        // STAGE 3-2
        if(branch == "Stage3-2"){music = "rave2.bor";    musicPlay(music, folder, 1);}
        // STAGEL 3-3
        if(branch == "Stage3-3"){music = "rave1.bor";    musicPlay(music, folder, 1);}

        // STAGE 4-1
        if(branch == "Stage4-1"){
            music = "egypt2.bor";
            musicPlay(music, folder, 1);
            setglobalvar("musicStopped", NULL()); //CLEAR THE VARIABLE TO BE USED IN THE NEXT LEVEL

        }

        // STAGE 4-2
        if(branch == "Stage4-2"){
            if(getglobalvar("musicStopped") != NULL()){
                music = "egypt2.bor";
                musicPlay(music, folder, 1);
                setglobalvar("musicStopped", NULL());
            }
        }


        // STAGE 5-1
        if(branch == "Stage5-1"){
            music = "china.bor";
            musicPlay(music, folder, 1);
            setglobalvar("musicStopped", NULL()); //CLEAR THE VARIABLE TO BE USED IN THE NEXT LEVEL

        }

        // STAGE 5-2
        if(branch == "Stage5-2"){
            if(getglobalvar("musicStopped") != NULL()){
                music = "china.bor";
                musicPlay(music, folder, 1);
                setglobalvar("musicStopped", NULL());
            }
        }

        // STAGE 6-1
        if(branch == "Stage6-1"){music = "jungle1.bor";    musicPlay(music, "root", 1);}

        // STAGE 6-2
        if(branch == "Stage6-2"){music = "jungle2.bor";    musicPlay(music, "root", 1);}

        // STAGE 6-3
        if(branch == "Stage6-3" && mStyle == 0){music = "rush.bor";    musicPlay(music, "root", 1);}
        if(branch == "Stage6-3"){music = "jungle3.bor";    musicPlay(music, "root", 1);}

        // STAGE 7-1
        // STAGE 7-2
        // STAGE 7-3

        // STAGE 8-1
        if(branch == "Stage8-1" && mStyle == 0){music = "manor1.bor";    musicPlay(music, "root", 1);}
        if(branch == "Stage8-1"){music = "menu.bor";    musicPlay(music, "root", 1);}

        // STAGE 8-2
        if(branch == "Stage8-2"){music = "manor2.bor";    musicPlay(music, "root", 1);}

        // STAGE 8-3
        if(branch == "Stage8-3"){music = "manor3.bor";    musicPlay(music, "root", 1);}


        // STAGE 8-4
        if(branch == "Stage8-4" && mStyle == 0){music = "manor4.bor";    musicPlay(music, "root", 1);}
        if(branch == "Stage8-4" && mStyle == 1){music = "roboss.bor";    musicPlay(music, "root", 1);}
        if(branch == "Stage8-4" && mStyle == 2){music = "manor3.bor";    musicPlay(music, "root", 1);}


        // STAGE 8-5: FINAL BOSS
        if(branch == "Stage8-5" && mStyle == 0){music = "manor5.bor";    musicPlay(music, "root", 1);}
        if(branch == "Stage8-5"){music = "manor4.bor";    musicPlay(music, "root", 1);}

        //ENDING
    }
    

    if(set == 2){
        // LEVEL 0-1
        if(branch == "Test0-1"){music = "rave1.bor";    musicPlay(music, "root", 1);}
        // LEVEL 0-2
        if(branch == "Test0-2"){music = "rave2.bor";    musicPlay(music, "root", 1);}
        // LEVEL 0-3
        if(branch == "Test0-3"){music = "rave1.bor";    musicPlay(music, "root", 1);}

        // LEVEL 1-1 AND LEVEL 1-2
        //HERE IS THE CORE OF THE MUSIC CONTINUATION LOGIC, YOU MUST FOLLOW THIS SAME STRUCTURE
        //THE "STOPMUSIC" OPTION IS "NO"?? ALL LEVELS BELOW WILL USE THE SAME MUSIC
        if(branch == "Test1-1"){
            music = "italy.bor";
            musicPlay(music, "root", 1);
            setglobalvar("musicStopped", NULL()); //CLEAR THE VARIABLE TO BE USED IN THE NEXT LEVEL
        }


        //THE VARIABLE "MUSICSTOPPED" WAS PREVIOUSLY SET TO 1 BY DEFAULT IN THE UPDATED.C AT THE TITLE SCREEN
        //IF THIS LEVEL WAS REACHED AFTER BEATING THE PREVIOUS LEVEL, IT MEANS THAT THE MUSIC IS ALREADY PLAYING AND NO NEED TO REPLAY
        //IF THIS LEVEL WAS REACHED DIRECTLY THROUGH LOADING OR LEVEL SELECTION, THE VARIABLE WAS NOT CLEARED AND THE MUSIC MUST BE REPLAYED
        // LEVEL 1-2
        if(branch == "Test1-2"){
            if(getglobalvar("musicStopped") != NULL()){
                music = "italy.bor";
                musicPlay(music, "root", 1);
                setglobalvar("musicStopped", NULL());
            }
        }

        // LEVEL 1-3
        if(branch == "Test1-3"){music = "versus.bor";    musicPlay(music, "root", 1);}
    }

}

void musicPlay(void music, void mStyle, int loop, int offset)
{//Play defined music, global usage function
    void folder;
    
    //GET CURRENT MUSIC STYLE
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}

    //SET LOOP TO ZERO IF NULL
    if(loop == NULL()){loop = 0;}

    //SET OFFSET TO ZERO IF NULL
    if(offset == NULL()){offset = 0;}

    //CHECK IF THE MUSIC WAS PLAYED BY USING GAME SETTINGS, SAVE ONLY IF WAS PLAYED "IN-LEVEL"
    setglobalvar("musicPlaying", music);

    //RESET THE FLAG USED FOR THE GAME SETTINGS CHECK
    setglobalvar("bgmPlay", NULL());

    //PLAY MUSIC
    fademusic(0);
    playmusic(folder+music, loop, offset);
}

void musicReplay()
{//Replay the current music if the style is changed in-game
    void music = getglobalvar("musicPlaying");
    void branch = openborvariant("current_branch");
    
    if(music != NULL()){
        if(openborvariant("in_level")){musicPlay(music, "root", 1);}
    }
}

I will try your method.
 
Not exactly, the engine will not look for these native musics in other folders than "data/music". However, you can use the updated.c to add more events where these scripted musics will be played, allowing you to select different folders for the menu/remix.bor too. You can see an example in the SOR2X when I play music during the "complete screen" or "game over" events.
I copied your scripts from your SOR2X mod, pasted them in my code, and modified them in mine for those events. At least I got it started, but somehow, they don't change music in menu after changing the music style. I got this new music misc.c here.

musicmisc.c:
C:
void musicIntro()
{//Play Intro scene music
    void mStyle;
    void folder;
    void music    = "remix.bor";

    //DETECT IF THE MUSIC STYLE VARIABLE IS ALREADY SAVED, OTHERWISE GET DIRECTLY FROM THE SOR2X.CFG FILE
    if(getglobalvar("musicStyle") == NULL()){

        //CFG FILE EXISTS?? GET VALUES FROM EXTERNAL CFG FILE
        if(openfilestream("saves/My Mod.cfg") != -1){
            void cfg    = openfilestream("saves/My Mod.cfg");
            int pos        = 0;
            int limit    = 29;

            if(getglobalvar("nextLine") == NULL()){setglobalvar("nextLine", 0);}

            while(getglobalvar("nextLine") < limit){
                filestreamnextline(cfg);
                setglobalvar("nextLine", getglobalvar("nextLine")+1);
            }

            if(getglobalvar("nextLine") >= limit){
                mStyle = getfilestreamargument(cfg, pos, "string");
                closefilestream(cfg);
            }
        }
        else //CFG FILE NOT EXISTS?? USE THE DEFAULT VALUE
        {
            mStyle = "root";
        }
    }
    else //MUSIC STYLE VARIABLE EXISTS?? GET MUSIC STYLE
    {
        mStyle = getglobalvar("musicStyle");
    }

    //PLAY DEFINED MUSIC
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}
    playmusic(folder+music, 0);
    setglobalvar("musicPlaying", music);
}


void musicSelect()
{//Play Select Screen music
    void mStyle = getglobalvar("musicStyle");
    void music  = "menu.bor";
    void folder;
  
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}
    playmusic(folder+music, 1);
    setglobalvar("musicPlaying", music);
}

void musicComplete()
{//Play Complete Screen music
    void mStyle = getglobalvar("musicStyle");
    void music  = "complete.bor";
    void folder;
  
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}
    playmusic(folder+music, 0);
    setglobalvar("musicPlaying", music);
}

void musicGameover()
{//Play Game over music
    void mStyle = getglobalvar("musicStyle");
    void music = "gameover.bor";
    void folder;
  
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}
    playmusic(folder+music, 0);
    setglobalvar("musicPlaying", music);
}

void musicReplay()
{//Replay the current music if the style is changed in-game
    void mStyle = getglobalvar("musicStyle");
    void music = getglobalvar("musicPlaying");
    void folder;
  
    if(music != NULL()){

        /*if(openborvariant("current_branch") == "sor2_st3i"){
            if(mStyle == "original" && music == "04.ogg"){music = "49.ogg";}else
            if(mStyle == "remake" && music == "49.ogg"){music = "04.ogg";}
        }*/

        if(mStyle == "custom"){folder = "data/music/";}//else{folder = "data/music/"+mStyle+"/";}
        if(openborvariant("in_level")){playmusic(folder+music, 1);}

    }
  
}

I haven't tested the intro yet with music.

EDIT: Tested. I just renamed my pak name of this project from "My Mod" to a new one. Plus, it still plays the green version of it after I changed it to Red. It still plays the green version as a default. Maybe it's because of my setting to "green" as default in musicIntro() function.

C:
void musicIntro()
{//Play Intro scene music
    void mStyle;
    void folder;
    void music    = "remix.bor";

    //DETECT IF THE MUSIC STYLE VARIABLE IS ALREADY SAVED, OTHERWISE GET DIRECTLY FROM THE SOR2X.CFG FILE
    if(getglobalvar("musicStyle") == NULL()){

        //CFG FILE EXISTS?? GET VALUES FROM EXTERNAL CFG FILE
        if(openfilestream("saves/ROD MAXED OUT!.cfg") != -1){
            void cfg    = openfilestream("saves/ROD MAXED OUT!.cfg");
            int pos        = 0;
            int limit    = 29;

            if(getglobalvar("nextLine") == NULL()){setglobalvar("nextLine", 0);}

            while(getglobalvar("nextLine") < limit){
                filestreamnextline(cfg);
                setglobalvar("nextLine", getglobalvar("nextLine")+1);
            }

            if(getglobalvar("nextLine") >= limit){
                mStyle = getfilestreamargument(cfg, pos, "string");
                closefilestream(cfg);
            }
        }
        else //CFG FILE NOT EXISTS?? USE THE DEFAULT VALUE
        {
            mStyle = "root";
        }
    }
    else //MUSIC STYLE VARIABLE EXISTS?? GET MUSIC STYLE
    {
        mStyle = getglobalvar("musicStyle");
    }

    //PLAY DEFINED MUSIC
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}
    playmusic(folder+music, 0);
    setglobalvar("musicPlaying", music);
}

A group of global music (remix.bor, menu.bor, complete.bor, and gameover.bor) is still not playing its respective music mode. Instead, I have the ones from the green version playing.

updated.c:
C:
#import "data/scripts/music.c"
#import "data/scripts/levelspawn/musicmisc.c"

void main(){
    //titleMusic();
    musicReturn();
}

void musicReturn()
{//Start all tasks
    
    if(openborvariant("in_titlescreen")){

        //FLAG USED TO INDICATE IF THE LEVEL MUSIC IS STOPPED TO THE "MUSICSTAGE.C" FUNCTIONS
        if(getglobalvar("musicStopped") != 1){setglobalvar("musicStopped", 1);}
    if(getglobalvar("mStyle") == NULL()){setglobalvar("mStyle", 0);}
    }

    if(openborvariant("in_level")){
        
        //RESTART MUSICS EVERYTIME THE SOUND MENU IS ACCESSED
        //USED BECAUSE SCRIPTED MUSICS DON'T RESTARTS AUTOMATICALLY IF THE PLAYER DISABLE/ENABLE IT IN THE SOUND MENU
        if(openborvariant("pause") && openborvariant("in_sound_options")){
            if(getglobalvar("soundMenu") == NULL()){setglobalvar("soundMenu", 1);}
        }
        else
        if(!openborvariant("pause")){
            if(getglobalvar("soundMenu") != NULL()){musicReplay();setglobalvar("soundMenu", NULL());}
        }
    }

    if(openborvariant("current_scene") == "data/scenes/howto.txt"){
        musicMenu();
    }

}

void musicMenu()
{//Draw a Menu in/out game

    //DRAW MENU
    if(openborvariant("current_scene") == "data/scenes/howto.txt"){
        void str;
        float hRes    = openborvariant("hresolution");
        int mStyle    = getglobalvar("mStyle");
        int align;
        int xDif    = 10;                //DIFFERENCE BETWEEN THE FIRST AND SECOND COLUMNS
        int xPos1    = (hRes/2)-xDif;    //BASE X POSITION, FIRST COLUMN (HIGHLIGHTED OPTIONS NAME)
        int xPos2    = (hRes/2)+xDif;    //BASE X POSITION, SECOND COLUMN (HIGHLIGHTED OPTIONS CHANGE)
        int yPos    = 60;                //BASE Y POSITION FOR ALL MENU CONTENT, USE THIS TO MOVE ALL OPTIONS TOGETHER
        int font    = 0;                //ALL FONTS BELOW CHANGES FROM 0 TO 1 IF THE OPTION IS HIGHLIGHTED
        int layer    = 1000000003;
        
        //OPTION TITLE
        str = "Music_Style:";align = xPos1-strwidth(str, font);
        drawstring(align, yPos, font, str, layer);

        //OPTION NAME
        if(mStyle == 0){str = "Green";}
        if(mStyle == 1){str = "Red";}
    if(mStyle == 2){str = "Blue";}
        drawstring(xPos2, yPos, font, str, layer);
    }
}

void titleMusic()
{
    if(openborvariant("in_menuscreen") || openborvariant("in_titlescreen"))
    {        
        if(getlocalvar("MusicMenu") == NULL())
        {
            playmusic("Data/Music/versus.bor", 1);
            setlocalvar("MusicMenu", 1);
        }
    }
    else {if(getlocalvar("MusicMenu") != NULL()) setlocalvar("MusicMenu", NULL());}
}
 
Last edited:
I copied your scripts from your SOR2X mod, pasted them in my code, and modified them in mine for those events. At least I got it started, but somehow, they don't change music in menu after changing the music style. I got this new music misc.c here.

musicmisc.c:
C:
void musicIntro()
{//Play Intro scene music
    void mStyle;
    void folder;
    void music    = "remix.bor";

    //DETECT IF THE MUSIC STYLE VARIABLE IS ALREADY SAVED, OTHERWISE GET DIRECTLY FROM THE SOR2X.CFG FILE
    if(getglobalvar("musicStyle") == NULL()){

        //CFG FILE EXISTS?? GET VALUES FROM EXTERNAL CFG FILE
        if(openfilestream("saves/My Mod.cfg") != -1){
            void cfg    = openfilestream("saves/My Mod.cfg");
            int pos        = 0;
            int limit    = 29;

            if(getglobalvar("nextLine") == NULL()){setglobalvar("nextLine", 0);}

            while(getglobalvar("nextLine") < limit){
                filestreamnextline(cfg);
                setglobalvar("nextLine", getglobalvar("nextLine")+1);
            }

            if(getglobalvar("nextLine") >= limit){
                mStyle = getfilestreamargument(cfg, pos, "string");
                closefilestream(cfg);
            }
        }
        else //CFG FILE NOT EXISTS?? USE THE DEFAULT VALUE
        {
            mStyle = "root";
        }
    }
    else //MUSIC STYLE VARIABLE EXISTS?? GET MUSIC STYLE
    {
        mStyle = getglobalvar("musicStyle");
    }

    //PLAY DEFINED MUSIC
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}
    playmusic(folder+music, 0);
    setglobalvar("musicPlaying", music);
}


void musicSelect()
{//Play Select Screen music
    void mStyle = getglobalvar("musicStyle");
    void music  = "menu.bor";
    void folder;
 
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}
    playmusic(folder+music, 1);
    setglobalvar("musicPlaying", music);
}

void musicComplete()
{//Play Complete Screen music
    void mStyle = getglobalvar("musicStyle");
    void music  = "complete.bor";
    void folder;
 
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}
    playmusic(folder+music, 0);
    setglobalvar("musicPlaying", music);
}

void musicGameover()
{//Play Game over music
    void mStyle = getglobalvar("musicStyle");
    void music = "gameover.bor";
    void folder;
 
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}
    playmusic(folder+music, 0);
    setglobalvar("musicPlaying", music);
}

void musicReplay()
{//Replay the current music if the style is changed in-game
    void mStyle = getglobalvar("musicStyle");
    void music = getglobalvar("musicPlaying");
    void folder;
 
    if(music != NULL()){

        /*if(openborvariant("current_branch") == "sor2_st3i"){
            if(mStyle == "original" && music == "04.ogg"){music = "49.ogg";}else
            if(mStyle == "remake" && music == "49.ogg"){music = "04.ogg";}
        }*/

        if(mStyle == "custom"){folder = "data/music/";}//else{folder = "data/music/"+mStyle+"/";}
        if(openborvariant("in_level")){playmusic(folder+music, 1);}

    }
 
}

I haven't tested the intro yet with music.

EDIT: Tested. I just renamed my pak name of this project from "My Mod" to a new one. Plus, it still plays the green version of it after I changed it to Red. It still plays the green version as a default. Maybe it's because of my setting to "green" as default in musicIntro() function.

C:
void musicIntro()
{//Play Intro scene music
    void mStyle;
    void folder;
    void music    = "remix.bor";

    //DETECT IF THE MUSIC STYLE VARIABLE IS ALREADY SAVED, OTHERWISE GET DIRECTLY FROM THE SOR2X.CFG FILE
    if(getglobalvar("musicStyle") == NULL()){

        //CFG FILE EXISTS?? GET VALUES FROM EXTERNAL CFG FILE
        if(openfilestream("saves/ROD MAXED OUT!.cfg") != -1){
            void cfg    = openfilestream("saves/ROD MAXED OUT!.cfg");
            int pos        = 0;
            int limit    = 29;

            if(getglobalvar("nextLine") == NULL()){setglobalvar("nextLine", 0);}

            while(getglobalvar("nextLine") < limit){
                filestreamnextline(cfg);
                setglobalvar("nextLine", getglobalvar("nextLine")+1);
            }

            if(getglobalvar("nextLine") >= limit){
                mStyle = getfilestreamargument(cfg, pos, "string");
                closefilestream(cfg);
            }
        }
        else //CFG FILE NOT EXISTS?? USE THE DEFAULT VALUE
        {
            mStyle = "root";
        }
    }
    else //MUSIC STYLE VARIABLE EXISTS?? GET MUSIC STYLE
    {
        mStyle = getglobalvar("musicStyle");
    }

    //PLAY DEFINED MUSIC
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}
    playmusic(folder+music, 0);
    setglobalvar("musicPlaying", music);
}

A group of global music (remix.bor, menu.bor, complete.bor, and gameover.bor) is still not playing its respective music mode. Instead, I have the ones from the green version playing.

updated.c:
C:
#import "data/scripts/music.c"
#import "data/scripts/levelspawn/musicmisc.c"

void main(){
    //titleMusic();
    musicReturn();
}

void musicReturn()
{//Start all tasks
  
    if(openborvariant("in_titlescreen")){

        //FLAG USED TO INDICATE IF THE LEVEL MUSIC IS STOPPED TO THE "MUSICSTAGE.C" FUNCTIONS
        if(getglobalvar("musicStopped") != 1){setglobalvar("musicStopped", 1);}
    if(getglobalvar("mStyle") == NULL()){setglobalvar("mStyle", 0);}
    }

    if(openborvariant("in_level")){
      
        //RESTART MUSICS EVERYTIME THE SOUND MENU IS ACCESSED
        //USED BECAUSE SCRIPTED MUSICS DON'T RESTARTS AUTOMATICALLY IF THE PLAYER DISABLE/ENABLE IT IN THE SOUND MENU
        if(openborvariant("pause") && openborvariant("in_sound_options")){
            if(getglobalvar("soundMenu") == NULL()){setglobalvar("soundMenu", 1);}
        }
        else
        if(!openborvariant("pause")){
            if(getglobalvar("soundMenu") != NULL()){musicReplay();setglobalvar("soundMenu", NULL());}
        }
    }

    if(openborvariant("current_scene") == "data/scenes/howto.txt"){
        musicMenu();
    }

}

void musicMenu()
{//Draw a Menu in/out game

    //DRAW MENU
    if(openborvariant("current_scene") == "data/scenes/howto.txt"){
        void str;
        float hRes    = openborvariant("hresolution");
        int mStyle    = getglobalvar("mStyle");
        int align;
        int xDif    = 10;                //DIFFERENCE BETWEEN THE FIRST AND SECOND COLUMNS
        int xPos1    = (hRes/2)-xDif;    //BASE X POSITION, FIRST COLUMN (HIGHLIGHTED OPTIONS NAME)
        int xPos2    = (hRes/2)+xDif;    //BASE X POSITION, SECOND COLUMN (HIGHLIGHTED OPTIONS CHANGE)
        int yPos    = 60;                //BASE Y POSITION FOR ALL MENU CONTENT, USE THIS TO MOVE ALL OPTIONS TOGETHER
        int font    = 0;                //ALL FONTS BELOW CHANGES FROM 0 TO 1 IF THE OPTION IS HIGHLIGHTED
        int layer    = 1000000003;
      
        //OPTION TITLE
        str = "Music_Style:";align = xPos1-strwidth(str, font);
        drawstring(align, yPos, font, str, layer);

        //OPTION NAME
        if(mStyle == 0){str = "Green";}
        if(mStyle == 1){str = "Red";}
    if(mStyle == 2){str = "Blue";}
        drawstring(xPos2, yPos, font, str, layer);
    }
}

void titleMusic()
{
    if(openborvariant("in_menuscreen") || openborvariant("in_titlescreen"))
    {      
        if(getlocalvar("MusicMenu") == NULL())
        {
            playmusic("Data/Music/versus.bor", 1);
            setlocalvar("MusicMenu", 1);
        }
    }
    else {if(getlocalvar("MusicMenu") != NULL()) setlocalvar("MusicMenu", NULL());}
}
@maxman I suggest not copying/pasting the entire code directly from a game to another, there's a high chance to not work. Instead, I suggest you read the code to understand the concept of how it works and build a new one specifically adapted for your game, same as we made with the step-by-step scripted music.

In addition, I suggest to centralize any music operation only in the musicPlay() function, this way you will have a default behaviour for every event where a music is needed.

As an example:

Not recommended
C:
void musicComplete()
{//Play Complete Screen music
    void mStyle = getglobalvar("musicStyle");
    void music  = "complete.bor";
    void folder;
 
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}
    playmusic(folder+music, 0);
    setglobalvar("musicPlaying", music);
}

Recommended
C:
void musicComplete()
{//Play Complete Screen music
    void mStyle = getglobalvar("musicStyle");
    void music  = "complete.bor";
    void folder;

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "subfolder1";}
    if(mStyle == 2){folder = "subfolder2";}
 
    musicPlay(music, folder, 1);
}

A group of global music (remix.bor, menu.bor, complete.bor, and gameover.bor) is still not playing its respective music mode. Instead, I have the ones from the green version playing.
Remember that the native engine music events will not be changed by the scripted musics. Instead, you must detect these events manually and then use the musicPlay() function to play it. Don't forget to change the native music names otherwise they will be detected by the engine and will be played automatically. As an example, you could change the remix.bor to 00.bor
 
I was replacing the "root" music style part with the folder varname in the musicReplay() function, but is it because I didn't specify the folder varname here?

C:
void musicReplay()
{//Replay the current music if the style is changed in-game
    void music = getglobalvar("musicPlaying");
    //void branch = openborvariant("current_branch");
 
    if(music != NULL()){
        if(openborvariant("in_level")){musicPlay(music, folder, 1);}
    }
}

Here's the log:
Code:
Total Ram: 4171603968 Bytes
 Free Ram: 1026891776 Bytes
 Used Ram: 6295552 Bytes

debug:nativeWidth, nativeHeight, bpp, Hz  1366, 768, 24, 60
OpenBoR v3.0 Build 6391, Compile Date: Apr  8 2020

Game Selected: ./Paks/ROD MAXED OUT!.pak

FileCaching System Init......    Disabled
Initializing video............
Reading video settings from 'data/video.txt'.
Initialized video.............    480x272 (Mode: 1)

Loading menu.txt.............    Done!
Loading fonts................    1 2 3 4 Done!
Timer init...................    Done!
Initialize Sound.............. 
Loading sprites..............    Done!
Loading level order..........    Done!
Loading model constants......    Done!
Loading script settings......    Done!
Loading scripts.............. 
Script compile error in 'data/scripts/music.c': folder line 223, column 56
Script error: failed to import 'data/scripts/music.c': failed to compile

********** An Error Occurred **********
*            Shutting Down            *

Can't compile script 'update'
Total Ram: 4171603968 Bytes
 Free Ram: 1023520768 Bytes
 Used Ram: 31870976 Bytes

Release level data...........
Done!

Release graphics data........    Done!
Release game data............


Release game data............    Done!
Release timer................    Done!
Release input hardware.......    Done!
Release sound system.........    Done!
Release FileCaching System...    Done!

**************** Done *****************

Can't compile script 'update'

P.S.: OK. I think I just fixed the musicReplay() function in music.c by adding the mStyle and folder variables. I think it's working after going back to load game(?).

C:
void musicReplay()
{//Replay the current music if the style is changed in-game
    void music = getglobalvar("musicPlaying");
    void folder;
    int mStyle = getglobalvar("mStyle");

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "Red";}
    if(mStyle == 2){folder = "Blue";}

    //GET CURRENT MUSIC STYLE
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}
   
    if(music != NULL()){
        if(openborvariant("in_level")){musicPlay(music, folder, 1);}
    }
}

Remember that the native engine music events will not be changed by the scripted musics. Instead, you must detect these events manually and then use the musicPlay() function to play it. Don't forget to change the native music names otherwise they will be detected by the engine and will be played automatically. As an example, you could change the remix.bor to 00.bor
Sounds like I have no other choice since I want to retain those names. However, I can change to different names if the engine always keeps detecting automatically.

Anyway, I just changed the names of those native music. The good thing is that it doesn't crash, but no music is playing.

musicmisc.c:
C:
//#import "data/scripts/music.c"

void musicIntro()
{//Play Intro scene music
    void mStyle;
    void folder;
    void music    = "title.bor";

    //DETECT IF THE MUSIC STYLE VARIABLE IS ALREADY SAVED, OTHERWISE GET DIRECTLY FROM THE SOR2X.CFG FILE
    if(getglobalvar("musicStyle") == NULL()){

        //CFG FILE EXISTS?? GET VALUES FROM EXTERNAL CFG FILE
        if(openfilestream("saves/ROD MAXED OUT!.cfg") != -1){
            void cfg    = openfilestream("saves/ROD MAXED OUT!.cfg");
            int pos        = 0;
            int limit    = 29;

            if(getglobalvar("nextLine") == NULL()){setglobalvar("nextLine", 0);}

            while(getglobalvar("nextLine") < limit){
                filestreamnextline(cfg);
                setglobalvar("nextLine", getglobalvar("nextLine")+1);
            }

            if(getglobalvar("nextLine") >= limit){
                mStyle = getfilestreamargument(cfg, pos, "string");
                closefilestream(cfg);
            }
        }
        else //CFG FILE NOT EXISTS?? USE THE DEFAULT VALUE
        {
            mStyle = "Green";
        }
    }
    else //MUSIC STYLE VARIABLE EXISTS?? GET MUSIC STYLE
    {
        mStyle = getglobalvar("musicStyle");
    }

    //PLAY DEFINED MUSIC
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}
    playmusic(folder+music, 0);
    setglobalvar("musicPlaying", music);
}


void musicSelect()
{//Play Select Screen music
    void mStyle = getglobalvar("musicStyle");
    void music  = "select.bor";
    void folder;

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "Red";}
    if(mStyle == 2){folder = "Blue";}
 
    musicPlay(music, folder, 1);
}

void musicComplete()
{//Play Complete Screen music
    void mStyle = getglobalvar("musicStyle");
    void music  = "finish.bor";
    void folder;

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "Red";}
    if(mStyle == 2){folder = "Blue";}
 
    musicPlay(music, folder, 1);
}

void musicGameover()
{//Play Game over music
    void mStyle = getglobalvar("musicStyle");
    void music  = "gameova.bor";
    void folder;

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "Red";}
    if(mStyle == 2){folder = "Blue";}
 
    musicPlay(music, folder, 1);
}

void musicPlay(void music, void mStyle, int loop, int offset)
{//Play defined music, global usage function
    void folder;
   
    //GET CURRENT MUSIC STYLE
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}

    //SET LOOP TO ZERO IF NULL
    if(loop == NULL()){loop = 0;}

    //SET OFFSET TO ZERO IF NULL
    if(offset == NULL()){offset = 0;}

    //CHECK IF THE MUSIC WAS PLAYED BY USING GAME SETTINGS, SAVE ONLY IF WAS PLAYED "IN-LEVEL"
    setglobalvar("musicPlaying", music);

    //RESET THE FLAG USED FOR THE GAME SETTINGS CHECK
    setglobalvar("bgmPlay", NULL());

    //PLAY MUSIC
    fademusic(0);
    playmusic(folder+music, loop, offset);
}

void musicReplay()
{//Replay the current music if the style is changed in-game
    void mStyle = getglobalvar("musicStyle");
    void music = getglobalvar("musicPlaying");
    void folder;

   
    if(music != NULL()){
        if(openborvariant("in_level")){musicPlay(music, folder, 1);}
    }
   
}

Am I missing some things again?

Just some partial parts in music.c.

C:
void musicPlay(void music, void mStyle, int loop, int offset)
{//Play defined music, global usage function
    void folder;
   
    //GET CURRENT MUSIC STYLE
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}

    if(mStyle == "root"){
        if(music == "miami.bor"){offset = 632124.53;} // Stage 1 loop
        if(music == "italy.bor"){offset = 372394.78;} // Stage 2
        if(music == "rave2.bor"){offset = 152420.37;} // Stage 3-2
        if(music == "egypt1.bor"){offset = 647968.13;} // Stage 4-0
        if(music == "egypt2.bor"){offset = 318913.43;} // Stage 4-1
        //if(music == "egypt1.ogg"){offset = 647939.25;}
    }

    //SET LOOP TO ZERO IF NULL
    if(loop == NULL()){loop = 0;}

    //SET OFFSET TO ZERO IF NULL
    if(offset == NULL()){offset = 0;}

    //CHECK IF THE MUSIC WAS PLAYED BY USING GAME SETTINGS, SAVE ONLY IF WAS PLAYED "IN-LEVEL"
    setglobalvar("musicPlaying", music);

    //RESET THE FLAG USED FOR THE GAME SETTINGS CHECK
    setglobalvar("bgmPlay", NULL());

    //PLAY MUSIC
    fademusic(0);
    playmusic(folder+music, loop, offset);
}

void musicReplay()
{//Replay the current music if the style is changed in-game
    void music = getglobalvar("musicPlaying");
    void folder;
    int mStyle = getglobalvar("mStyle");

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "Red";}
    if(mStyle == 2){folder = "Blue";}

    //GET CURRENT MUSIC STYLE
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}
   
    if(music != NULL()){
        if(openborvariant("in_level")){musicPlay(music, folder, 1);}
    }
}
 
Last edited:
P.S.: OK. I think I just fixed the musicReplay() function in music.c by adding the mStyle and folder variables. I think it's working after going back to load game(?).
@maxman You don't need to define paths again once it's already defined in the musicPlay() script. I suggest removing the line below.

1692562237384.png

Then, the script will look like this, you only need to get the mStyle variable and translate to a folder's name, not the entire path:
C:
void musicReplay()
{//Replay the current music if the style is changed in-game
    void music = getglobalvar("musicPlaying");
    void folder;
    int mStyle = getglobalvar("mStyle");

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "Red";}
    if(mStyle == 2){folder = "Blue";}

    if(music != NULL()){
        if(openborvariant("in_level")){musicPlay(music, folder, 1);}
    }
}

Anyway, I just changed the names of those native music. The good thing is that it doesn't crash, but no music is playing.
What music is not playing? And how are you currently detecting the events like game over or complete screen?
 
What music is not playing? And how are you currently detecting the events like game over or complete screen?
I renamed these names to different ones in the following:
remix.bor -> title.bor
menu.bor -> select.bor
complete.bor -> finish.bor
gameover.bor -> gameova.bor

I do not know how to detect the events.

Here's my current updated.c.

C:
#import "data/scripts/music.c"
#import "data/scripts/levelspawn/musicmisc.c"

void main(){
    //titleMusic();
    //Pausing();
    musicReturn();
}

void musicReturn()
{//Start all tasks
   
    if(openborvariant("in_titlescreen")){

        //FLAG USED TO INDICATE IF THE LEVEL MUSIC IS STOPPED TO THE "MUSICSTAGE.C" FUNCTIONS
        if(getglobalvar("musicStopped") != 1){setglobalvar("musicStopped", 1);}
    if(getglobalvar("mStyle") == NULL()){setglobalvar("mStyle", 0);}
    }

    if(openborvariant("in_level")){
       
        //RESTART MUSICS EVERYTIME THE SOUND MENU IS ACCESSED
        //USED BECAUSE SCRIPTED MUSICS DON'T RESTARTS AUTOMATICALLY IF THE PLAYER DISABLE/ENABLE IT IN THE SOUND MENU
        if(openborvariant("pause") && openborvariant("in_sound_options")){
            if(getglobalvar("soundMenu") == NULL()){setglobalvar("soundMenu", 1);}
        }
        else
        if(!openborvariant("pause")){
            if(getglobalvar("soundMenu") != NULL()){musicReplay();setglobalvar("soundMenu", NULL());}
        }
    }

    if(openborvariant("current_scene") == "data/scenes/howto.txt"){
        musicMenu();
    }

}

void musicMenu()
{//Draw a Menu in/out game

    //DRAW MENU
    if(openborvariant("current_scene") == "data/scenes/howto.txt"){
        void str;
        float hRes    = openborvariant("hresolution");
        int mStyle    = getglobalvar("mStyle");
        int align;
        int xDif    = 10;                //DIFFERENCE BETWEEN THE FIRST AND SECOND COLUMNS
        int xPos1    = (hRes/2)-xDif;    //BASE X POSITION, FIRST COLUMN (HIGHLIGHTED OPTIONS NAME)
        int xPos2    = (hRes/2)+xDif;    //BASE X POSITION, SECOND COLUMN (HIGHLIGHTED OPTIONS CHANGE)
        int yPos    = 60;                //BASE Y POSITION FOR ALL MENU CONTENT, USE THIS TO MOVE ALL OPTIONS TOGETHER
        int font    = 0;                //ALL FONTS BELOW CHANGES FROM 0 TO 1 IF THE OPTION IS HIGHLIGHTED
        int layer    = 1000000003;
       
        //OPTION TITLE
        str = "Music_Style:";align = xPos1-strwidth(str, font);
        drawstring(align, yPos, font, str, layer);

        //OPTION NAME
        if(mStyle == 0){str = "Green";}
        if(mStyle == 1){str = "Red";}
    if(mStyle == 2){str = "Blue";}
        drawstring(xPos2, yPos, font, str, layer);
    }
}

void titleMusic()
{
    if(openborvariant("in_menuscreen") || openborvariant("in_titlescreen"))
    {       
        if(getlocalvar("MusicMenu") == NULL())
        {
            playmusic("Data/Music/versus.bor", 1);
            setlocalvar("MusicMenu", 1);
        }
    }
    else {if(getlocalvar("MusicMenu") != NULL()) setlocalvar("MusicMenu", NULL());}
}

void Pausing()
{
    //NECESSARY STEP TO RESET THE "MENU OPTION" VARIABLE AT THE TITLE SCREEN
    if(openborvariant("in_titlescreen")){
        if(getglobalvar("menuPause") != 0){setglobalvar("menuPause", 0);}
    }

    //CHECK IF THE PLAYER IS IN A LEVEL
    if(openborvariant("in_level")){
        int volume        = openborvariant("effectvol");
        int speed        = 100;
        int loop        = 0;
        int menuPause    = getglobalvar("menuPause");
        int max            = 3;
        int min            = 0;
        int add            = 1;

        //CHECK IF THE GAME IS PAUSED BUT NOT IN OPTIONS
        if(openborvariant("game_paused") && !openborvariant("in_options")){

            //DETECT UP/DOWN BUTTON PRESS AND CHANGE THE HIGHLIGHTED OPTION
            if(    playerkeys(0, 1, "movedown")||
                playerkeys(1, 1, "movedown")||
                playerkeys(2, 1, "movedown")||
                playerkeys(3, 1, "movedown")){
               
                if(menuPause >= min && menuPause < max){setglobalvar("menuPause", menuPause+add);}
                if(menuPause == max){setglobalvar("menuPause", min);}
            }
            if(    playerkeys(0, 1, "moveup")||
                playerkeys(1, 1, "moveup")||
                playerkeys(2, 1, "moveup")||
                playerkeys(3, 1, "moveup")){
               
                if(menuPause > min && menuPause <= max){setglobalvar("menuPause", menuPause-add);}
                if(menuPause == min){setglobalvar("menuPause", max);}
            }

            //DEFINE A FUNCTION TO BE EXECUTED WHEN EACH OPTION IS CONFIRMED BY PRESSING ACTION KEYS
            //NOTE THAT SOME OPTIONS ALREADY PLAY SAMPLES NATIVELY, ONLY A FEW NEED TO BE MANUALLY PLAYED
            if(    playerkeys(0, 1, "anybutton")||
                playerkeys(1, 1, "anybutton")||
                playerkeys(2, 1, "anybutton")||
                playerkeys(3, 1, "anybutton")){
               
                //LOCK NATIVE KEYS
                changeplayerproperty(0, "newkeys", 0);
                changeplayerproperty(1, "newkeys", 0);
                changeplayerproperty(2, "newkeys", 0);
                changeplayerproperty(3, "newkeys", 0);

                //CONTINUE
                if(menuPause == 0){
                    changeplayerproperty(0, "newkeys", openborconstant("FLAG_ESC"));
                }

                //OPTIONS
                if(menuPause == 1){
                    playsample(openborconstant("SAMPLE_BEEP2"), 0, volume, volume, speed, loop);
                    options();
                }

                //HOW TO PLAY
                if(menuPause == 2){
                    playsample(openborconstant("SAMPLE_BEEP2"), 0, volume, volume, speed, loop);
                    setglobalvar("menuPause", 0);
                    playgif("data/scenes/howto.gif");
                }

                //END GAME
                if(menuPause == 3){
                    changeplayerproperty(0, "newkeys", openborconstant("FLAG_ESC"));
                }
            }

            //TEXTS, IMAGES AND EFFECTS
            void str;
            float hRes        = openborvariant("hresolution");
            int align;
            int yPos        = 80;
            int fontPause    = 3;
            int font0        = 0;
            int font1        = 0;
            int font2        = 0;
            int font3        = 0;
            int yAdd        = 11;
            int layer        = -1000000003;

            //DEFINE FONTS TO HIGHLIGHTED OPTIONS
            if(getglobalvar("menuPause") == 0){font0 = 1;}else    //IS CONTINUE HIGHLIGHTED??
            if(getglobalvar("menuPause") == 1){font1 = 1;}else    //IS OPTIONS HIGHLIGHTED??
            if(getglobalvar("menuPause") == 2){font2 = 1;}else    //IS HOW TO PLAY HIGHLIGHTED??
            if(getglobalvar("menuPause") == 3){font3 = 1;}        //IS END GAME HIGHLIGHTED??

            str = "Pause";align = (hRes-(strwidth(str, fontPause)))/2;
            drawstring(align, yPos, fontPause, str, layer);

            yPos = yPos+yAdd*3;
            str = "Continue";align = (hRes-(strwidth(str, font0)))/2;
            drawstring(align, yPos, font0, str, layer);

            yPos = yPos+yAdd;
            str = "Options";align = (hRes-(strwidth(str, font1)))/2;
            drawstring(align, yPos, font1, str, layer);

            yPos = yPos+yAdd;
            str = "How To Play";align = (hRes-(strwidth(str, font2)))/2;
            drawstring(align, yPos, font2, str, layer);

            yPos = yPos+yAdd;
            str = "End Game";align = (hRes-(strwidth(str, font3)))/2;
            drawstring(align, yPos, font3, str, layer);
        }

        //LOCK ACTION KEYS, NECESSARY STEP TO QUIT FROM THE OPTIONS IGNORING THE NATIVE "END GAME" OPTION
        if(openborvariant("game_paused") && openborvariant("in_options")){
            changeplayerproperty(0, "newkeys", 0);
            changeplayerproperty(1, "newkeys", 0);
            changeplayerproperty(2, "newkeys", 0);
            changeplayerproperty(3, "newkeys", 0);
        }

        //NECESSARY STEPS THAT NEEDS TO RUN AFTER SOME OPTIONS LIKE "END GAME" ARE CONFIRMED
        //THERE'S A FEW ENGINE FUNCTIONS THAT ONLY RUNS OUTSIDE OF THE PAUSE MENU
        if(!openborvariant("game_paused") && !openborvariant("in_options")){

            //END GAME
            if(menuPause == 3){gameover();}
        }
    }
}

update.c:
Code:
#import "data/scripts/dc_bug_patch/continue_timer.c"
//#import "data/scripts/menu/pauseMenu.c"
//#import "data/scripts/spawn/musicplay.c"
//#import "data/scripts/spawn/musicmisc.c"
#import "data/scripts/music.c"

void oncreate()
{
}

void ondestroy()
{
}

void main()
{
    /*
    * Execute the bug patch function. 
    * The numeric value is allowed
    * continue time in game seconds. 
    * Native engine default is 10.
    */
    int continue_time = 20;

    dc_continue_bug_patch(continue_time);

    LastNumber();
    //trainingPause();
    //titleMusic();
    pausingGo();
    //Versus()

    /*if(openborvariant("in_titlescreen")){
        if(getglobalvar("musicStopped") != 1){
            setglobalvar("musicStopped", 1);
        }
    }*/
    goStartDaMusic();
}

void goStartDaMusic(){

    
    if(openborvariant("in_titlescreen")){
        //FLAG USED TO INDICATE IF THE LEVEL MUSIC IS STOPPED TO THE "MUSICSTAGE.C" FUNCTIONS
        if(getglobalvar("musicStopped") != 1){
            setglobalvar("musicStopped", 1);
        }
    }

    if(openborvariant("in_level")){
        //RESTART MUSICS EVERYTIME THE SOUND MENU IS ACCESSED
        //USED BECAUSE SCRIPTED MUSICS DON'T RESTARTS AUTOMATICALLY IF THE PLAYER DISABLE/ENABLE IT IN THE SOUND MENU
        if(openborvariant("pause") && openborvariant("in_sound_options")){
            if(getglobalvar("soundMenu") == NULL()){
                setglobalvar("soundMenu", 1);
            }
        }else if(!openborvariant("pause")){
            if(getglobalvar("soundMenu") != NULL()){
                musicReplay();
                setglobalvar("soundMenu", NULL());
            }
        }

    }

}

void titleMusic()
{
    if(openborvariant("in_menuscreen") || openborvariant("in_titlescreen"))
    {        
        if(getlocalvar("MusicMenu") == NULL())
        {
            playmusic("Data/Music/versus.bor", 1);
            setlocalvar("MusicMenu", 1);
        }
    }
    else {if(getlocalvar("MusicMenu") != NULL()) setlocalvar("MusicMenu", NULL());}
}

/*
void versus()
{//
    if(openborvariant("in_menuscreen")==1){
      setglobalvar("Plays", 0);
      setglobalvar("Win1", 0);
      setglobalvar("Win2", 0);
    } else if(openborvariant("in_selectscreen")){
      void set = openborvariant("current_set");

      if(set==1){
        setglobalvar("Plays", 2);
      }
    }
}

*/

void LastNumber()
{

    if(openborvariant("in_level"))
    {
        int P1 = getplayerproperty(0, "entity");
        int P2 = getplayerproperty(1, "entity");
        int P1Life = getplayerproperty(0, "lives");
        int P2Life = getplayerproperty(1, "lives");

        if(P1)
        {
            drawstring(131, 2, 3, P1Life-1);
        }

        if(P2)
        {
            drawstring(311, 2, 3, P2Life-1);
        }

    }
}

void pausingGo()
{
    //NECESSARY STEP TO RESET THE "MENU OPTION" VARIABLE AT THE TITLE SCREEN
    if(openborvariant("in_titlescreen")){
        if(getglobalvar("menuPause") != 0){setglobalvar("menuPause", 0);}
    }

    //CHECK IF THE PLAYER IS IN A LEVEL
    if(openborvariant("in_level") /*&& openborvariant("current_set") < 2*/){
        int volume        = openborvariant("effectvol");
        int speed        = 100;
        int loop        = 0;
        int menuPause    = getglobalvar("menuPause");
        int max            = 3;
        int min            = 0;
        int add            = 1;

        //CHECK IF THE GAME IS PAUSED BUT NOT IN OPTIONS
        if(openborvariant("game_paused") && !openborvariant("in_options")){

            //DETECT UP/DOWN BUTTON PRESS AND CHANGE THE HIGHLIGHTED OPTION
            if(    playerkeys(0, 1, "movedown")||
                playerkeys(1, 1, "movedown")||
                playerkeys(2, 1, "movedown")||
                playerkeys(3, 1, "movedown")){
                
                if(menuPause >= min && menuPause < max){setglobalvar("menuPause", menuPause+add);}
                if(menuPause == max){setglobalvar("menuPause", min);}
            }
            if(    playerkeys(0, 1, "moveup")||
                playerkeys(1, 1, "moveup")||
                playerkeys(2, 1, "moveup")||
                playerkeys(3, 1, "moveup")){
                
                if(menuPause > min && menuPause <= max){setglobalvar("menuPause", menuPause-add);}
                if(menuPause == min){setglobalvar("menuPause", max);}
            }

            //DEFINE A FUNCTION TO BE EXECUTED WHEN EACH OPTION IS CONFIRMED BY PRESSING ACTION KEYS
            //NOTE THAT SOME OPTIONS ALREADY PLAY SAMPLES NATIVELY, ONLY A FEW NEED TO BE MANUALLY PLAYED
            if(    playerkeys(0, 1, "anybutton")||
                playerkeys(1, 1, "anybutton")||
                playerkeys(2, 1, "anybutton")||
                playerkeys(3, 1, "anybutton")){
                
                //LOCK NATIVE KEYS
                changeplayerproperty(0, "newkeys", 0);
                changeplayerproperty(1, "newkeys", 0);
                changeplayerproperty(2, "newkeys", 0);
                changeplayerproperty(3, "newkeys", 0);

                //CONTINUE
                if(menuPause == 0){
                    changeplayerproperty(0, "newkeys", openborconstant("FLAG_ESC"));
                    changeplayerproperty(1, "newkeys", openborconstant("FLAG_ESC"));
                    changeplayerproperty(2, "newkeys", openborconstant("FLAG_ESC"));
                    changeplayerproperty(3, "newkeys", openborconstant("FLAG_ESC"));
                }

                //OPTIONS
                if(menuPause == 1){
                    playsample(openborconstant("SAMPLE_BEEP2"), 0, volume, volume, speed, loop);
                    options();
                }

                //HOW TO PLAY
                if(menuPause == 2){
                    playsample(openborconstant("SAMPLE_BEEP2"), 0, volume, volume, speed, loop);
                    setglobalvar("menuPause", 0);
                    playgif("data/scenes/howto.gif");
                }

                //END GAME
                if(menuPause == 3){
                    changeplayerproperty(0, "newkeys", openborconstant("FLAG_ESC"));
                    changeplayerproperty(1, "newkeys", openborconstant("FLAG_ESC"));
                    changeplayerproperty(2, "newkeys", openborconstant("FLAG_ESC"));
                    changeplayerproperty(3, "newkeys", openborconstant("FLAG_ESC"));
                }
            }

            //TEXTS, IMAGES AND EFFECTS
            void str;
            float hRes        = openborvariant("hresolution");
            int align;
            int yPos        = 80;
            int fontPause    = 3;
            int font0        = 0;
            int font1        = 0;
            int font2        = 0;
            int font3        = 0;
            int yAdd        = 11;
            int layer        = -1000000003;

            //DEFINE FONTS TO HIGHLIGHTED OPTIONS
            if(getglobalvar("menuPause") == 0){font0 = 1;}else    //IS CONTINUE HIGHLIGHTED??
            if(getglobalvar("menuPause") == 1){font1 = 1;}else    //IS OPTIONS HIGHLIGHTED??
            if(getglobalvar("menuPause") == 2){font2 = 1;}else    //IS HOW TO PLAY HIGHLIGHTED??
            if(getglobalvar("menuPause") == 3){font3 = 1;}        //IS END GAME HIGHLIGHTED??

            str = "Pause";align = (hRes-(strwidth(str, fontPause)))/2;
            drawstring(align, yPos, fontPause, str, layer);

            yPos = yPos+yAdd*3;
            str = "Continue";align = (hRes-(strwidth(str, font0)))/2;
            drawstring(align, yPos, font0, str, layer);

            yPos = yPos+yAdd;
            str = "Options";align = (hRes-(strwidth(str, font1)))/2;
            drawstring(align, yPos, font1, str, layer);

            yPos = yPos+yAdd;
            str = "How To Play";align = (hRes-(strwidth(str, font2)))/2;
            drawstring(align, yPos, font2, str, layer);

            yPos = yPos+yAdd;
            str = "End Game";align = (hRes-(strwidth(str, font3)))/2;
            drawstring(align, yPos, font3, str, layer);
        }

        //LOCK ACTION KEYS, NECESSARY STEP TO QUIT FROM THE OPTIONS IGNORING THE NATIVE "END GAME" OPTION
        if(openborvariant("game_paused") && openborvariant("in_options")){
            changeplayerproperty(0, "newkeys", 0);
            changeplayerproperty(1, "newkeys", 0);
            changeplayerproperty(2, "newkeys", 0);
            changeplayerproperty(3, "newkeys", 0);
        }

        //NECESSARY STEPS THAT NEED TO RUN AFTER SOME OPTIONS LIKE "END GAME" ARE CONFIRMED
        //THERE'S A FEW ENGINE FUNCTIONS THAT ONLY RUN OUTSIDE OF THE PAUSE MENU
        if(!openborvariant("game_paused") && !openborvariant("in_options")){

            //END GAME
            if(menuPause == 3){gameover();}
        }
    }
}
 
I do not know how to detect the events.
First we need to import the music.c content to the updated.c

C:
#import "data/scripts/music.c"

You can use the openborvariants to detect events inside the updated. If I'm not wrong the void oncreate() can be used to run tasks once (I never tested to be honest), but let's stick with the void main().
So, now the variable "musicPlaying" will be useful to check what music is currently playing, then we can run a certain task to play another music until the current one is different from the desired one.

C:
void main()
{
    if(openborvariant("in_titlescreen")){
        
        //CHECK THE CURRENT MUSIC TO PLAY IT ONCE
        if(getglobalvar("musicPlaying") != "title.bor"){
            musicTitle();
        }
    }
    if(openborvariant("in_selectscreen")){
        
        //CHECK THE CURRENT MUSIC TO PLAY IT ONCE
        if(getglobalvar("musicPlaying") != "select.bor"){
            musicSelect();
        }
    }
    if(openborvariant("in_showcomplete")){
        
        //CHECK THE CURRENT MUSIC TO PLAY IT ONCE
        if(getglobalvar("musicPlaying") != "finish.bor"){
            musicFinish();
        }
    }
    if(openborvariant("current_scene") == "data/scenes/gameover.txt"){
        
        //CHECK THE CURRENT MUSIC TO PLAY IT ONCE
        if(getglobalvar("musicPlaying") != "gameova.bor"){
            musicGameova();
        }
    }
}

And finally we can build the music script for each event inside the music.c like this. As an option, you can reduce the codes and make these scripts directly inside the event's detection, but usually I make them separated because in SORX the scripts are reusable and I want to maintain a default behaviour everytime I call a certain function in more than one event, but it's your decision.
C:
void musicTitle()
{//Play Title Screen music
    void mStyle = getglobalvar("musicStyle");
    void music  = "title.bor";
    void folder;

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "Red";}
    if(mStyle == 2){folder = "Blue";}
 
    musicPlay(music, folder, 1);
}

void musicSelect()
{//Play Select Screen music
    void mStyle = getglobalvar("musicStyle");
    void music  = "select.bor";
    void folder;

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "Red";}
    if(mStyle == 2){folder = "Blue";}
 
    musicPlay(music, folder, 1);
}

void musicFinish()
{//Play Complete Screen music
    void mStyle = getglobalvar("musicStyle");
    void music  = "finish.bor";
    void folder;

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "Red";}
    if(mStyle == 2){folder = "Blue";}
 
    musicPlay(music, folder, 1);
}

void musicGameova()
{//Play Game over music
    void mStyle = getglobalvar("musicStyle");
    void music  = "gameova.bor";
    void folder;

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "Red";}
    if(mStyle == 2){folder = "Blue";}
 
    musicPlay(music, folder, 1);
}
 
Thanks, Kratus. Here is my current update of my music.c file/content after importing music.c and musicmisc.c to updated.c. However, I don't understand why it's not working.

updated.c:
C:
#import "data/scripts/music.c"
#import "data/scripts/levelspawn/musicmisc.c"

void main(){
    //titleMusic();
    //Pausing();
    musicReturn();

    if(openborvariant("in_titlescreen")){
      
        //CHECK THE CURRENT MUSIC TO PLAY IT ONCE
        if(getglobalvar("musicPlaying") != "title.bor"){
            musicTitle();
        }
    }
    if(openborvariant("in_selectscreen")){
      
        //CHECK THE CURRENT MUSIC TO PLAY IT ONCE
        if(getglobalvar("musicPlaying") != "select.bor"){
            musicSelect();
        }
    }
    if(openborvariant("in_showcomplete")){
      
        //CHECK THE CURRENT MUSIC TO PLAY IT ONCE
        if(getglobalvar("musicPlaying") != "finish.bor"){
            musicFinish();
        }
    }
    if(openborvariant("current_scene") == "data/scenes/gameover.txt"){
      
        //CHECK THE CURRENT MUSIC TO PLAY IT ONCE
        if(getglobalvar("musicPlaying") != "gameova.bor"){
            musicGameova();
        }
    }
}

void musicReturn()
{//Start all tasks
  
    if(openborvariant("in_titlescreen")){

        //FLAG USED TO INDICATE IF THE LEVEL MUSIC IS STOPPED TO THE "MUSICSTAGE.C" FUNCTIONS
        if(getglobalvar("musicStopped") != 1){setglobalvar("musicStopped", 1);}
    if(getglobalvar("mStyle") == NULL()){setglobalvar("mStyle", 0);}
    }

    if(openborvariant("in_level")){
      
        //RESTART MUSICS EVERYTIME THE SOUND MENU IS ACCESSED
        //USED BECAUSE SCRIPTED MUSICS DON'T RESTARTS AUTOMATICALLY IF THE PLAYER DISABLE/ENABLE IT IN THE SOUND MENU
        if(openborvariant("pause") && openborvariant("in_sound_options")){
            if(getglobalvar("soundMenu") == NULL()){setglobalvar("soundMenu", 1);}
        }
        else
        if(!openborvariant("pause")){
            if(getglobalvar("soundMenu") != NULL()){musicReplay();setglobalvar("soundMenu", NULL());}
        }
    }

    if(openborvariant("current_scene") == "data/scenes/howto.txt"){
        musicMenu();
    }

}

void musicMenu()
{//Draw a Menu in/out game

    //DRAW MENU
    if(openborvariant("current_scene") == "data/scenes/howto.txt"){
        void str;
        float hRes    = openborvariant("hresolution");
        int mStyle    = getglobalvar("mStyle");
        int align;
        int xDif    = 10;                //DIFFERENCE BETWEEN THE FIRST AND SECOND COLUMNS
        int xPos1    = (hRes/2)-xDif;    //BASE X POSITION, FIRST COLUMN (HIGHLIGHTED OPTIONS NAME)
        int xPos2    = (hRes/2)+xDif;    //BASE X POSITION, SECOND COLUMN (HIGHLIGHTED OPTIONS CHANGE)
        int yPos    = 60;                //BASE Y POSITION FOR ALL MENU CONTENT, USE THIS TO MOVE ALL OPTIONS TOGETHER
        int font    = 0;                //ALL FONTS BELOW CHANGES FROM 0 TO 1 IF THE OPTION IS HIGHLIGHTED
        int layer    = 1000000003;
      
        //OPTION TITLE
        str = "Music_Style:";align = xPos1-strwidth(str, font);
        drawstring(align, yPos, font, str, layer);

        //OPTION NAME
        if(mStyle == 0){str = "Green";}
        if(mStyle == 1){str = "Red";}
    if(mStyle == 2){str = "Blue";}
        drawstring(xPos2, yPos, font, str, layer);
    }
}

void titleMusic()
{
    if(openborvariant("in_menuscreen") || openborvariant("in_titlescreen"))
    {      
        if(getlocalvar("MusicMenu") == NULL())
        {
            playmusic("Data/Music/versus.bor", 1);
            setlocalvar("MusicMenu", 1);
        }
    }
    else {if(getlocalvar("MusicMenu") != NULL()) setlocalvar("MusicMenu", NULL());}
}

music.c:
C:
void musicStage()
{//Play music in each stage
 //musicStopped global variable usage: 1 = Stage music is Stopped / NULL() = Stage music is Playing
    void branch    = openborvariant("current_branch");
    void music;
    void folder;
    int stopMusic;
    int set    = openborvariant("current_set");
    int mStyle = getglobalvar("mStyle");

  
    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "Red";}
    if(mStyle == 2){folder = "Blue";}
  
  
    if(set == 0){

        // STAGE 1
        //if(branch == "Stage1"){music = "miami.bor";    musicPlay(music, "root", 1, 628562.9198609781);}
        //if(branch == "Stage1"){music = "miami.bor";    musicPlay(music, folder, 1, 632124.53);} // No need to loop songs with same name in music folders

        //if(branch == "Stage1" && mStyle == 0){music = "miami.bor";    musicPlay(music, folder, 1, 632124.53);} // For music looping purpose
        if(branch == "Stage1"){music = "miami.bor";    musicPlay(music, folder, 1);}


        // STAGE 2-1 AND LEVEL 2-2
        //HERE IS THE CORE OF THE MUSIC CONTINUATION LOGIC, YOU MUST FOLLOW THIS SAME STRUCTURE
        //THE "STOPMUSIC" OPTION IS "NO"?? ALL LEVELS BELOW WILL USE THE SAME MUSIC

        if(branch == "Stage2-1"){
            music = "italy.bor";
            musicPlay(music, folder, 1);
            setglobalvar("musicStopped", NULL()); //CLEAR THE VARIABLE TO BE USED IN THE NEXT LEVEL
        }


        //THE VARIABLE "MUSICSTOPPED" WAS PREVIOUSLY SET TO 1 BY DEFAULT IN THE UPDATED.C AT THE TITLE SCREEN
        //IF THIS LEVEL WAS REACHED AFTER BEATING THE PREVIOUS LEVEL, IT MEANS THAT THE MUSIC IS ALREADY PLAYING AND NO NEED TO REPLAY
        //IF THIS LEVEL WAS REACHED DIRECTLY THROUGH LOADING OR LEVEL SELECTION, THE VARIABLE WAS NOT CLEARED AND THE MUSIC MUST BE REPLAYED

        // STAGE 2-2

        if(branch == "Stage2-2"){
            if(getglobalvar("musicStopped") != NULL()){
                music = "italy.bor";
                musicPlay(music, folder, 1);
                setglobalvar("musicStopped", NULL());
            }
        }

        // STAGE 3-1
        if(branch == "Stage3-1"){music = "rave1.bor";    musicPlay(music, folder, 1);}
        // STAGE 3-2
        if(branch == "Stage3-2"){music = "rave2.bor";    musicPlay(music, folder, 1);}
        // STAGEL 3-3
        if(branch == "Stage3-3"){music = "rave1.bor";    musicPlay(music, folder, 1);}

        // STAGE 4-0
        //if(branch == "Stage4-0" && mStyle == 0){music = "egypt1.bor";    musicPlay(music, folder, 1, 647968.12);}
        if(branch == "Stage4-0"){music = "egypt1.bor";    musicPlay(music, folder, 1);}
        //if(branch == "Stage4-0"){music = "egypt1.ogg";    musicPlay(music, folder, 1);}

        // STAGE 4-1
        if(branch == "Stage4-1"){
            music = "egypt2.bor";
            musicPlay(music, folder, 1);
            setglobalvar("musicStopped", NULL()); //CLEAR THE VARIABLE TO BE USED IN THE NEXT LEVEL

        }

        // STAGE 4-2
        if(branch == "Stage4-2"){
            if(getglobalvar("musicStopped") != NULL()){
                music = "egypt2.bor";
                musicPlay(music, folder, 1);
                setglobalvar("musicStopped", NULL());
            }
        }


        // STAGE 5-1
        if(branch == "Stage5-1"){
            music = "china.bor";
            musicPlay(music, folder, 1);
            setglobalvar("musicStopped", NULL()); //CLEAR THE VARIABLE TO BE USED IN THE NEXT LEVEL

        }

        // STAGE 5-2
        if(branch == "Stage5-2"){
            if(getglobalvar("musicStopped") != NULL()){
                music = "china.bor";
                musicPlay(music, folder, 1);
                setglobalvar("musicStopped", NULL());
            }
        }

        // STAGE 6-1
        if(branch == "Stage6-1"){music = "jungle1.bor";    musicPlay(music, folder, 1);}

        // STAGE 6-2
        if(branch == "Stage6-2"){music = "jungle2.bor";    musicPlay(music, folder, 1);}

        // STAGE 6-3
        if(branch == "Stage6-3" && mStyle == 0){music = "rush.bor";    musicPlay(music, "root", 1);}
        if(branch == "Stage6-3"){music = "jungle3.bor";    musicPlay(music, folder, 1);}

        // STAGE 7-1
        if(branch == "Stage7-1"){music = "japan1.bor";    musicPlay(music, folder, 1);}
        // STAGE 7-2
        if(branch == "Stage7-2"){music = "japan2.bor";    musicPlay(music, folder, 1);}
        // STAGE 7-3
        if(branch == "Stage7-3"){music = "japan3.bor";    musicPlay(music, folder, 1);}

        // STAGE 8-1
        if(branch == "Stage8-1" && mStyle == "root"){music = "manor1.bor";    musicPlay(music, "root", 1);}
        if(branch == "Stage8-1"){music = "menu.bor";    musicPlay(music, folder, 1);}


        // STAGE 8-2
        if(branch == "Stage8-2"){music = "manor2.bor";    musicPlay(music, folder, 1);}

        // STAGE 8-3
        if(branch == "Stage8-3"){music = "manor3.bor";    musicPlay(music, folder, 1);}


        // STAGE 8-4
        if(branch == "Stage8-4" && mStyle == "root"){music = "manor4.bor";    musicPlay(music, "root", 1);}
        if(branch == "Stage8-4" && mStyle == "Red"){music = "roboss.bor";    musicPlay(music, "Red", 1);}
        if(branch == "Stage8-4" && mStyle == "Blue"){music = "manor3.bor";    musicPlay(music, "Blue", 1);}


        // STAGE 8-5: FINAL BOSS
        if(branch == "Stage8-5" && mStyle == 0){music = "manor5.bor";    musicPlay(music, "root", 1);}
        if(branch == "Stage8-5"){music = "manor4.bor";    musicPlay(music, folder, 1);}

        //ENDING
    }
  

    if(set == 2){
        // LEVEL 0-1
        //if(branch == "Test0-1"){music = "rave1.bor";    musicPlay(music, "root", 1);}

        if(branch == "Test0-1"){music = "rave1.bor";    musicPlay(music, folder, 1);}
        // LEVEL 0-2
        //if(branch == "Test0-2"){music = "rave2.bor";    musicPlay(music, "root", 1);}

        if(branch == "Test0-2"){music = "rave2.bor";    musicPlay(music, folder, 1);}
        // LEVEL 0-3
        //if(branch == "Test0-3"){music = "rave1.bor";    musicPlay(music, "root", 1);}

        if(branch == "Test0-3"){music = "rave1.bor";    musicPlay(music, folder, 1);}

        // LEVEL 1-1 AND LEVEL 1-2
        //HERE IS THE CORE OF THE MUSIC CONTINUATION LOGIC, YOU MUST FOLLOW THIS SAME STRUCTURE
        //THE "STOPMUSIC" OPTION IS "NO"?? ALL LEVELS BELOW WILL USE THE SAME MUSIC
        if(branch == "Test1-1"){
            music = "italy.bor";
            musicPlay(music, folder, 1);
            setglobalvar("musicStopped", NULL()); //CLEAR THE VARIABLE TO BE USED IN THE NEXT LEVEL
        }


        //THE VARIABLE "MUSICSTOPPED" WAS PREVIOUSLY SET TO 1 BY DEFAULT IN THE UPDATED.C AT THE TITLE SCREEN
        //IF THIS LEVEL WAS REACHED AFTER BEATING THE PREVIOUS LEVEL, IT MEANS THAT THE MUSIC IS ALREADY PLAYING AND NO NEED TO REPLAY
        //IF THIS LEVEL WAS REACHED DIRECTLY THROUGH LOADING OR LEVEL SELECTION, THE VARIABLE WAS NOT CLEARED AND THE MUSIC MUST BE REPLAYED
        // LEVEL 1-2
        if(branch == "Test1-2"){
            if(getglobalvar("musicStopped") != NULL()){
                music = "italy.bor";
                musicPlay(music, folder, 1);
                setglobalvar("musicStopped", NULL());
            }
        }

        // LEVEL 1-3
        if(branch == "Test1-3"){music = "versus.bor";    musicPlay(music, "root", 1);}
    }

}

void musicTitle()
{//Play Title Screen music
    void mStyle = getglobalvar("musicStyle");
    void music  = "title.bor";
    void folder;

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "Red";}
    if(mStyle == 2){folder = "Blue";}
 
    musicPlay(music, folder, 1);
}

void musicSelect()
{//Play Select Screen music
    void mStyle = getglobalvar("musicStyle");
    void music  = "select.bor";
    void folder;

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "Red";}
    if(mStyle == 2){folder = "Blue";}
 
    musicPlay(music, folder, 1);
}

void musicFinish()
{//Play Complete Screen music
    void mStyle = getglobalvar("musicStyle");
    void music  = "finish.bor";
    void folder;

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "Red";}
    if(mStyle == 2){folder = "Blue";}
 
    musicPlay(music, folder, 1);
}

void musicGameova()
{//Play Game over music
    void mStyle = getglobalvar("musicStyle");
    void music  = "gameova.bor";
    void folder;

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "Red";}
    if(mStyle == 2){folder = "Blue";}
 
    musicPlay(music, folder, 1);
}

void musicPlay(void music, void mStyle, int loop, int offset)
{//Play defined music, global usage function
    void folder;
  
    //GET CURRENT MUSIC STYLE
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}

    if(mStyle == "root"){
        if(music == "miami.bor"){offset = 632124.53;} // Stage 1 loop
        if(music == "italy.bor"){offset = 372394.78;} // Stage 2
        if(music == "rave2.bor"){offset = 152420.37;} // Stage 3-2
        if(music == "egypt1.bor"){offset = 647968.13;} // Stage 4
        if(music == "egypt2.bor"){offset = 318913.43;} // Stage 4
        if(music = "china.bor"){offset = 776163.32;} // Stage 5
        //if(music == "egypt1.ogg"){offset = 647939.25;}
    }

    /*
    if(mStyle == "Red"){
      
    }
    */

    //SET LOOP TO ZERO IF NULL
    if(loop == NULL()){loop = 0;}

    //SET OFFSET TO ZERO IF NULL
    if(offset == NULL()){offset = 0;}

    //CHECK IF THE MUSIC WAS PLAYED BY USING GAME SETTINGS, SAVE ONLY IF WAS PLAYED "IN-LEVEL"
    setglobalvar("musicPlaying", music);

    //RESET THE FLAG USED FOR THE GAME SETTINGS CHECK
    setglobalvar("bgmPlay", NULL());

    //PLAY MUSIC
    fademusic(0);
    playmusic(folder+music, loop, offset);
}

void musicReplay()
{//Replay the current music if the style is changed in-game
    void music = getglobalvar("musicPlaying");
    void folder;
    int mStyle = getglobalvar("mStyle");

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "Red";}
    if(mStyle == 2){folder = "Blue";}

    if(music != NULL()){
        if(openborvariant("in_level")){musicPlay(music, folder, 1);}
    }
}

musicmisc.c:
C:
//#import "data/scripts/music.c"

void musicTitle()
{//Play Title Screen music
    void mStyle = getglobalvar("musicStyle");
    void music  = "title.bor";
    void folder;

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "Red";}
    if(mStyle == 2){folder = "Blue";}
 
    musicPlay(music, folder, 1);
}

void musicSelect()
{//Play Select Screen music
    void mStyle = getglobalvar("musicStyle");
    void music  = "select.bor";
    void folder;

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "Red";}
    if(mStyle == 2){folder = "Blue";}
 
    musicPlay(music, folder, 1);
}

void musicFinish()
{//Play Complete Screen music
    void mStyle = getglobalvar("musicStyle");
    void music  = "finish.bor";
    void folder;

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "Red";}
    if(mStyle == 2){folder = "Blue";}
 
    musicPlay(music, folder, 1);
}

void musicGameova()
{//Play Game over music
    void mStyle = getglobalvar("musicStyle");
    void music  = "gameova.bor";
    void folder;

    if(mStyle == 0){folder = "root";}
    if(mStyle == 1){folder = "Red";}
    if(mStyle == 2){folder = "Blue";}
 
    musicPlay(music, folder, 1);
}

void musicPlay(void music, void mStyle, int loop, int offset)
{//Play defined music, global usage function
    void folder;
  
    //GET CURRENT MUSIC STYLE
    if(mStyle == "root"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}

    //SET LOOP TO ZERO IF NULL
    if(loop == NULL()){loop = 0;}

    //SET OFFSET TO ZERO IF NULL
    if(offset == NULL()){offset = 0;}

    //CHECK IF THE MUSIC WAS PLAYED BY USING GAME SETTINGS, SAVE ONLY IF WAS PLAYED "IN-LEVEL"
    setglobalvar("musicPlaying", music);

    //RESET THE FLAG USED FOR THE GAME SETTINGS CHECK
    setglobalvar("bgmPlay", NULL());

    //PLAY MUSIC
    fademusic(0);
    playmusic(folder+music, loop, offset);
}

void musicReplay()
{//Replay the current music if the style is changed in-game
    void mStyle = getglobalvar("musicStyle");
    void music = getglobalvar("musicPlaying");
    void folder;

    if(music != NULL()){
        if(openborvariant("in_level")){musicPlay(music, folder, 1);}
    }
  
}

I have not made gameover.txt yet.
 
Last edited:
@maxman Please, don't post all scripts at once because it's confusing to understand and the post is too long to read. Let's focus only on the one that is not working, and then we can go to the others.
Give me some minutes and I will test it in a BOR mod first.
 
Back
Top Bottom