Musicoverlap question

StrikerX

Member
In metrovania games, using branchs,when I configure musicoverlap 1 in levels.txt, setting the song's address in the first stage, the following ones continue to play that song (as long as I don't set music on them). OK. The problem is when the load game, the music is not played. What to do? Use nosave in all stages except the first?
 
I believe this is a similar question you are asking for.

Thanks for replay. I tried the script, but music does not play

musicoverlap.txt
Code:
name    musicoverlap
type    none
lifespan  10
shadow    0

animationscript data/scripts/musicoverlap.c

anim idle
     loop      0
     delay     6
     offset    100 43
     frame     data/chars/misc/empty.gif
     @cmd     musicPlay "ag21.ogg" 0
     frame     data/chars/misc/empty.gif

anim follow1
     loop      0
     delay     6
     offset    100 43
     frame     data/chars/misc/empty.gif
     @cmd     musicReplay
     frame     data/chars/misc/empty.gif

Stage01.txt
Code:
# play ag 21
spawn musicoverlap
at 0

Stage02.txt
Code:
# replay ag 21
spawn musicoverlap
@script
void main()
    {
    void self = getlocalvar("self");
    performattack(self, openborconstant("ANI_FOLLOW1"));
       }
@end_script
at 0
 
What's your animation script for musicPlay and musicReplay like? Nevermind the question I asked. Now I know where they come from.

@Kratus has that music script setup in his latest SOR2X mod which you listen to in the next stage (e.g. stage 1-2) with the previous music playing from the beginning (stage 1-1). The next stage has no music playing, but with music in script. You go back to Load Game to where you left off and listen to the previous music that was playing from the beginning. He set it up the stages with branch which is quite better.

This code part is from his SOR2X and it's already declared/#imported from his updated.c. Take a look at stage 3 from SOR2 route.

main_musicstage.c:
C:
#import "data/scripts/levelspawn/main_musicboss.c"

void musicStage()
{//Play music in each stage
 //musicStopped global variable usage: 1 = Stage music is Stopped / NULL() = Stage music is Playing
    void mStyle = getglobalvar("musicStyle");
    void branch = openborvariant("current_branch");
    void music;
    void folder;
    int set     = openborvariant("current_set");
    int stage     = openborvariant("current_stage");
    int stopMusic;
 
    if(mStyle == "custom"){folder = "Musics/";}else{folder = "data/music/"+mStyle+"/";}
 
    if(set == 0 || set == 2){
        //MAIN ROUTE//
        if(branch == "route"){music = "24.ogg";        playmusic(folder+music, 1);}
    
        //SOR2 ROUTE
    
        //STAGE 1
        if(branch == "sor2_st1a"){music = "02.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor2_st1b"){music = "03.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor2_st1c"){music = 0;        playmusic(folder+music, 1);}
    
        //STAGE 2
        if(branch == "sor2_st2a"){music = "05.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor2_st2b"){music = "06.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor2_st2c"){music = "05.ogg";    playmusic(folder+music, 1);}
    
        //STAGE 3
        stopMusic = "no"; //IF YOU DON'T WANT THE MUSIC TO COTINUE ALONG THE NEXT LEVELS, SIMPLY FILL "YES"

        if(stopMusic == "no"){ //THE "STOPMUSIC" OPTION IS "NO"?? ALL LEVELS BELOW WILL USE THE SAME MUSIC
            if(branch == "sor2_st3a"){music = "07.ogg";playmusic(folder+music, 1);setglobalvar("musicStopped", NULL());}
            if(branch == "sor2_st3b"){if(getglobalvar("musicStopped") != NULL()){music = "07.ogg";playmusic(folder+music, 1);setglobalvar("musicStopped", NULL());}}
            if(branch == "sor2_st3c"){if(getglobalvar("musicStopped") != NULL()){music = "07.ogg";playmusic(folder+music, 1);setglobalvar("musicStopped", NULL());}}
            if(branch == "sor2_st3d"){if(getglobalvar("musicStopped") != NULL()){music = "07.ogg";playmusic(folder+music, 1);setglobalvar("musicStopped", NULL());}}
        }
        else
        if(stopMusic == "yes"){ //THE "STOPMUSIC" OPTION IS "YES"?? EACH LEVEL BELOW WILL USE THE DEFINED MUSIC
            if(branch == "sor2_st3a"){music = "07.ogg";    playmusic(folder+music, 1);} //DEFINE EACH MUSIC FOR EACH STAGE
            if(branch == "sor2_st3b"){music = "07.ogg";    playmusic(folder+music, 1);} //DEFINE EACH MUSIC FOR EACH STAGE
            if(branch == "sor2_st3c"){music = "07.ogg";    playmusic(folder+music, 1);} //DEFINE EACH MUSIC FOR EACH STAGE
            if(branch == "sor2_st3d"){music = "07.ogg";    playmusic(folder+music, 1);} //DEFINE EACH MUSIC FOR EACH STAGE
        }

        if(branch == "sor2_st3e"){music = "06.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor2_st3f"){music = "07.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor2_st3g"){music = "08.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor2_st3h"){music = "45.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor2_st3i"){music = "46.ogg";    playmusic(folder+music, 1);}
    
        //STAGE 4
        stopMusic = "no"; //IF YOU DON'T WANT THE MUSIC TO COTINUE ALONG THE NEXT LEVELS, SIMPLY FILL "YES"

        if(stopMusic == "no"){ //THE "STOPMUSIC" OPTION IS "NO"?? ALL LEVELS BELOW WILL USE THE SAME MUSIC
            if(branch == "sor2_st4a"){music = "09.ogg";playmusic(folder+music, 1);setglobalvar("musicStopped", NULL());}
            if(branch == "sor2_st4b"){if(getglobalvar("musicStopped") != NULL()){music = "09.ogg";playmusic(folder+music, 1);setglobalvar("musicStopped", NULL());}}
        }
        else
        if(stopMusic == "yes"){ //THE "STOPMUSIC" OPTION IS "YES"?? EACH LEVEL BELOW WILL USE THE DEFINED MUSIC
            if(branch == "sor2_st4a"){music = "09.ogg";    playmusic(folder+music, 1);} //DEFINE EACH MUSIC FOR EACH STAGE
            if(branch == "sor2_st4b"){music = "09.ogg";    playmusic(folder+music, 1);} //DEFINE EACH MUSIC FOR EACH STAGE
        }

        if(branch == "sor2_st4c"){music = "10.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor2_st4d"){music = 0;        playmusic(folder+music, 1);}
    
        //STAGE 5
        stopMusic = "no"; //IF YOU DON'T WANT THE MUSIC TO COTINUE ALONG THE NEXT LEVELS, SIMPLY FILL "YES"

        if(stopMusic == "no"){ //THE "STOPMUSIC" OPTION IS "NO"?? ALL LEVELS BELOW WILL USE THE SAME MUSIC
            if(branch == "sor2_st5a"){music = "11.ogg";playmusic(folder+music, 1);setglobalvar("musicStopped", NULL());}
            if(branch == "sor2_st5b"){if(getglobalvar("musicStopped") != NULL()){music = "11.ogg";playmusic(folder+music, 1);setglobalvar("musicStopped", NULL());}}
            if(branch == "sor2_st5c"){if(getglobalvar("musicStopped") != NULL()){music = "11.ogg";playmusic(folder+music, 1);setglobalvar("musicStopped", NULL());}}
        }
        else
        if(stopMusic == "yes"){ //THE "STOPMUSIC" OPTION IS "YES"?? EACH LEVEL BELOW WILL USE THE DEFINED MUSIC
            if(branch == "sor2_st5a"){music = "11.ogg";    playmusic(folder+music, 1);} //DEFINE EACH MUSIC FOR EACH STAGE
            if(branch == "sor2_st5b"){music = "11.ogg";    playmusic(folder+music, 1);} //DEFINE EACH MUSIC FOR EACH STAGE
            if(branch == "sor2_st5c"){music = "11.ogg";    playmusic(folder+music, 1);} //DEFINE EACH MUSIC FOR EACH STAGE
        }
    
        //STAGE 6
        if(branch == "sor2_st6a"){music = "12.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor2_st6b"){music = "13.ogg";    playmusic(folder+music, 1);}
    
        //STAGE 7
        if(branch == "sor2_st7a"){music = "14.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor2_st7b"){music = "15.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor2_st7c"){music = "47.ogg";    playmusic(folder+music, 1);}
    
        //STAGE 8
        stopMusic = "no"; //IF YOU DON'T WANT THE MUSIC TO COTINUE ALONG THE NEXT LEVELS, SIMPLY FILL "YES"

        if(stopMusic == "no"){ //THE "STOPMUSIC" OPTION IS "NO"?? ALL LEVELS BELOW WILL USE THE SAME MUSIC
            if(branch == "sor2_st8a"){music = "16.ogg";playmusic(folder+music, 1);setglobalvar("musicStopped", NULL());}
            if(branch == "sor2_st8b"){if(getglobalvar("musicStopped") != NULL()){music = "16.ogg";playmusic(folder+music, 1);setglobalvar("musicStopped", NULL());}}
        }
        else
        if(stopMusic == "yes"){ //THE "STOPMUSIC" OPTION IS "YES"?? EACH LEVEL BELOW WILL USE THE DEFINED MUSIC
            if(branch == "sor2_st8a"){music = "16.ogg";    playmusic(folder+music, 1);} //DEFINE EACH MUSIC FOR EACH STAGE
            if(branch == "sor2_st8b"){music = "16.ogg";    playmusic(folder+music, 1);} //DEFINE EACH MUSIC FOR EACH STAGE
        }
    
        //SOR3 ROUTE
    
        //STAGE 1
        if(branch == "sor3_st1a"){music = "21.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor3_st1b"){music = "22.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor3_st1c"){music = "24.ogg";    playmusic(folder+music, 1);}
    
        //STAGE 2
        if(branch == "sor3_st2a"){music = "25.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor3_st2b"){music = "26.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor3_st2c"){music = 0;        playmusic(folder+music, 1);}
    
        //STAGE 3
        if(branch == "sor3_st3a"){music = "28.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor3_st3b"){music = "29.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor3_st3c"){music = "30.ogg";    playmusic(folder+music, 1);}
    
        //STAGE 4
        if(branch == "sor3_st4a"){music = "31.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor3_st4b"){music = "32.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor3_st4c"){music = "33.ogg";    playmusic(folder+music, 1);}
    
        //STAGE 5
        stopMusic = "no"; //IF YOU DON'T WANT THE MUSIC TO COTINUE ALONG THE NEXT LEVELS, SIMPLY FILL "YES"

        if(stopMusic == "no"){ //THE "STOPMUSIC" OPTION IS "NO"?? ALL LEVELS BELOW WILL USE THE SAME MUSIC
            if(branch == "sor3_st5a"){music = "34.ogg";playmusic(folder+music, 1);setglobalvar("musicStopped", NULL());}
            if(branch == "sor3_st5b"){if(getglobalvar("musicStopped") != NULL()){music = "34.ogg";playmusic(folder+music, 1);setglobalvar("musicStopped", NULL());}}
            if(branch == "sor3_st5c"){if(getglobalvar("musicStopped") != NULL()){music = "34.ogg";playmusic(folder+music, 1);setglobalvar("musicStopped", NULL());}}
        }
        else
        if(stopMusic == "yes"){ //THE "STOPMUSIC" OPTION IS "YES"?? EACH LEVEL BELOW WILL USE THE DEFINED MUSIC
            if(branch == "sor3_st5a"){music = "34.ogg";    playmusic(folder+music, 1);} //DEFINE EACH MUSIC FOR EACH STAGE
            if(branch == "sor3_st5b"){music = "34.ogg";    playmusic(folder+music, 1);} //DEFINE EACH MUSIC FOR EACH STAGE
            if(branch == "sor3_st5c"){music = "34.ogg";    playmusic(folder+music, 1);} //DEFINE EACH MUSIC FOR EACH STAGE
        }

        if(branch == "sor3_st5d"){music = "35.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor3_st5e"){music = "25.ogg";    playmusic(folder+music, 1);}
    
        //STAGE 6
        if(branch == "sor3_st6a"){music = "21.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor3_st6b"){music = "22.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor3_st6c"){music = "22.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor3_st6d"){music = "22.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor3_st6e"){music = "22.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor3_st6f"){music = "37.ogg";    playmusic(folder+music, 1);}
    
        //STAGE 7
        stopMusic = "no"; //IF YOU DON'T WANT THE MUSIC TO COTINUE ALONG THE NEXT LEVELS, SIMPLY FILL "YES"

        if(stopMusic == "no"){ //THE "STOPMUSIC" OPTION IS "NO"?? ALL LEVELS BELOW WILL USE THE SAME MUSIC
            if(branch == "sor3_st7a"){music = "38.ogg";playmusic(folder+music, 1);setglobalvar("musicStopped", NULL());}
            if(branch == "sor3_st7b"){if(getglobalvar("musicStopped") != NULL()){music = "38.ogg";playmusic(folder+music, 1);setglobalvar("musicStopped", NULL());}}
        }
        else
        if(stopMusic == "yes"){ //THE "STOPMUSIC" OPTION IS "YES"?? EACH LEVEL BELOW WILL USE THE DEFINED MUSIC
            if(branch == "sor3_st7a"){music = "38.ogg";    playmusic(folder+music, 1);} //DEFINE EACH MUSIC FOR EACH STAGE
            if(branch == "sor3_st7b"){music = "38.ogg";    playmusic(folder+music, 1);} //DEFINE EACH MUSIC FOR EACH STAGE
        }

        if(branch == "sor3_st7c"){music = 0;        playmusic(folder+music, 1);}
        if(branch == "sor3_st7d"){music = "44.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor3_st7e"){music = "44.ogg";    playmusic(folder+music, 1);}
    
        //STAGE 8
        if(branch == "sor3_st8a"){music = "24.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor3_st8b"){music = "25.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor3_st8c"){music = "39.ogg";    playmusic(folder+music, 1);}
        if(branch == "sor3_st8d"){music = "40.ogg";playmusic(folder+music, 1);setglobalvar("musicStopped", 1);}
        if(branch == "sor3_st8e"){music = "21.ogg";playmusic(folder+music, 1);}

        setglobalvar("musicPlaying", music);
    }
 
    if(set == 1){ //SURVIVAL
        if(branch == "survival_config"){
            music = "24.ogg";
            playmusic(folder+music, 1);
            setglobalvar("musicPlaying", music);
        }else{
            musicBossX();
        }
    }
}

You also need a globalvar of "musicStopped" for it to stop.

Stage 3 in levels.txt:
Code:
#STAGE 3
branch            sor2_st3a
z                180 270
file            data/levels/sor2/st3a.txt    #PARK A
branch            sor2_st3b
z                140 426
file            data/levels/sor2/st3b.txt    #ARCADE
branch            sor2_st3c
z                220 270
file            data/levels/sor2/st3c.txt    #PIRATES 1F
branch            sor2_st3d
z                220 270
file            data/levels/sor2/st3d.txt    #PIRATES 2F
branch            sor2_st3e
z                234 270
file            data/levels/sor2/st3e.txt    #PIRATES 3F
branch            sor2_st3f
z                180 270
file            data/levels/sor2/st3f.txt    #PARK B
branch            sor2_st3g
z                180 270
file            data/levels/sor2/st3g.txt    #ALIEN CAVE ZAMZA
next
branch            sor2_st3h
z                190 270
file            data/levels/sor2/st3h.txt    #LAVA BRIDGE
branch            sor2_st3i
z                170 270
file            data/levels/sor2/st3i.txt    #TRACKER'S LAIR
next
 
Last edited:
I think I also need this but seeing the script is very long seems like it will be complicated o_O
is there another, simpler way?
@machok
The size gives the impression of being complicated but indeed it's not too much. Basically this script runs in the level.c when any level starts and if the variable musicStopped is not NULL(), the music will be replayed (usually if you go through a level select or load game) otherwise the script will be ignored and the current music will continue.
You could apply it only in levels where the music will not be interrupted, the others can use the normal music command in the level file.
 
@Kratus - if i am not mistaken, then this long script allows you to detect the last music that was playing before quiting the game or losing all you lives and at least allow it to continue on the same tune it was using (not from the same spot, but at least its the same soundtrack)

can this be modified to allow for a different file in case of reload?

example , long "ice level.ogg" track plays , but if player loses or quits , at the time of reload the level loads "ice level part 2.ogg"
 
@machok
The size gives the impression of being complicated but indeed it's not too much. Basically this script runs in the level.c when any level starts and if the variable musicStopped is not NULL(), the music will be replayed (usually if you go through a level select or load game) otherwise the script will be ignored and the current music will continue.
You could apply it only in levels where the music will not be interrupted, the others can use the normal music command in the level file.

My problems is since I use branch (in Levels.TXT) all my music always repeats from the beginning as I enter each new stage
so I think I need to write all my levels into the script and this is what makes it seem complicated. If this is the only way then I need carefully learn the script first to avoid mistakes and error, I understand the script looks like it's just a repetition but I have to be conscientious

set ARCADE_DEMO_v2.9
credits 5

lives 2
nosame 1 2
noshare 1
canSave 2
continuescore 2
musicoverlap 1

Branch Start1
z 208 247 160
file data/levels/Mission_Start.txt
Branch Start2
z 170 237 160
file data/levels/Mission_Start2.txt
Branch Start3
z 195 231 160
file data/levels/Mission_Start3.txt

and go on....
 
@Kratus Here's my main problem when I want to use only just default. It's separated into 2 music folders. I'm trying to put it to one as a test. I'll put 3 later. (As of now, it's empty in the green folder.)
C:
if(mStyle == "custom"){folder = "Musics/";}else{folder = "data/music/"+mStyle+"/";}

8-10-2023 4-53-28 PM.png8-10-2023 4-54-14 PM.png8-10-2023 4-54-34 PM.png

Also, I was able to make the music script without a crash, but still, no music is playing.

I just found where musicReplay is. How can I change the custom folder directory into a general music folder directory?

C:
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()){

        //TEMPORARY SOLUTION UNTIL ALL SOR TRACKS ARE ADDED, IT WILL PLAY GG/SMS TRACKS ON SPECIFIC ORIGINAL LEVELS
        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 = "Musics/";}else{folder = "data/music/"+mStyle+"/";}
        if(openborvariant("in_level")){playmusic(folder+music, 1);}
    }
}
 
Last edited:
@Kratus Here's my main problem when I want to use only just default. It's separated into 2 music folders. I'm trying to put it to one as a test. I'll put 3 later. (As of now, it's empty in the green folder.)
C:
if(mStyle == "custom"){folder = "Musics/";}else{folder = "data/music/"+mStyle+"/";}
I didn't understand your question, are you trying to use the "musics" root folder as a playlist option? Don't forget that my music scripts are connected to the game settings menu in order to change the style, you will need a menu in case you are trying to replicate the same feature.

I just found where musicReplay is. How can I change the custom folder directory into a general music folder directory?
If I understand your question correctly, just change the path to "data/music/" instead of only "Musics/".
 
If I understand your question correctly, just change the path to "data/music/" instead of only "Musics/".
Thanks. I figured that out when I was offline before your post.

I didn't understand your question, are you trying to use the "musics" root folder as a playlist option? Don't forget that my music scripts are connected to the game settings menu in order to change the style, you will need a menu in case you are trying to replicate the same feature.
Here's my setup which I created for replaying music and forgot to post. You take a look at musicPlaying() function in update.c here, but I'm only gonna show the music parts here.

update.c:
C-like:
#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"

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);
        }
    }*/
    musicPlaying();
}

void musicPlaying(){

 
    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());
            }
        }

    }

}

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

    //if(mStyle == "custom"){folder = "Musics/";}else{folder = "data/music/"+mStyle+"/";}
    //if(folder == "data/music/";

    if(set == 2){
        // MUSIC TEST IN LEVELS
        stopMusic = "no";

        if(stopMusic == "no"){
            if(branch == "Test1-1"){
                music = "italy.bor";
                playmusic("data/music/"+music, 1);
                //playmusic("data/music/italy.bor", 1);
                setglobalvar("musicStopped", NULL());
            }
            if(branch == "Test1-2"){
                if(getglobalvar("musicStopped") != NULL()){
                    music = "italy.bor";
                    playmusic("data/music/"+music, 1);
                    //playmusic("data/music/italy.bor", 1);
                    setglobalvar("musicStopped", NULL());
                }
            }
        }else if(stopMusic == "yes")
        {
            if(branch == "Test1-1"){
                music = "italy.bor";
                playmusic("data/music/"+music, 1);
                //playmusic("data/music/italy.bor", 1);
            }
            if(branch == "Test1-2"){
                music = "italy.bor";
                playmusic("data/music/"+music, 1);
                //playmusic("data/music/italy.bor", 1);
            }
        }
    }
}

musicmisc.c:
C:
void musicReplay()
{//Replay the current music if the style is changed in-game
    void mStyle = getglobalvar("musicStyle");
    void music  = getglobalvar("musicPlaying");
    void folder;
    void branch = openborvariant("current_branch");
 
    /*if(music != NULL()){

        //TEMPORARY SOLUTION UNTIL ALL SOR TRACKS ARE ADDED, IT WILL PLAY GG/SMS TRACKS ON SPECIFIC ORIGINAL LEVELS
        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 = "Musics/";}else{folder = "data/music/"+mStyle+"/";}
        if(openborvariant("in_level")){playmusic(folder+music, 1);}
    }*/

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

}

levels.txt for set 2 (third game mode) as a music play test:
Code:
set    Music_Play_Test
nosame    1
branch    Test1-1
musicoverlap 1
file    data/levels/test1-1.txt
branch    Test1-2
file    data/levels/test1-2.txt

Still, the music doesn't play. Am I missing something? Should I use updated.c for this to play?
 
Last edited:
Thanks. I figured that out when I was offline before your post.


Here's my setup which I created for replaying music and forgot to post. You take a look at musicPlaying() function in update.c here, but I'm only gonna show the music parts here.

update.c:
C-like:
#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"

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);
        }
    }*/
    musicPlaying();
}

void musicPlaying(){

 
    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());
            }
        }

    }

}

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

    //if(mStyle == "custom"){folder = "Musics/";}else{folder = "data/music/"+mStyle+"/";}
    //if(folder == "data/music/";

    if(set == 2){
        // MUSIC TEST IN LEVELS
        stopMusic = "no";

        if(stopMusic == "no"){
            if(branch == "Test1-1"){
                music = "italy.bor";
                playmusic("data/music/"+music, 1);
                //playmusic("data/music/italy.bor", 1);
                setglobalvar("musicStopped", NULL());
            }
            if(branch == "Test1-2"){
                if(getglobalvar("musicStopped") != NULL()){
                    music = "italy.bor";
                    playmusic("data/music/"+music, 1);
                    //playmusic("data/music/italy.bor", 1);
                    setglobalvar("musicStopped", NULL());
                }
            }
        }else if(stopMusic == "yes")
        {
            if(branch == "Test1-1"){
                music = "italy.bor";
                playmusic("data/music/"+music, 1);
                //playmusic("data/music/italy.bor", 1);
            }
            if(branch == "Test1-2"){
                music = "italy.bor";
                playmusic("data/music/"+music, 1);
                //playmusic("data/music/italy.bor", 1);
            }
        }
    }
}

musicmisc.c:
C:
void musicReplay()
{//Replay the current music if the style is changed in-game
    void mStyle = getglobalvar("musicStyle");
    void music  = getglobalvar("musicPlaying");
    void folder;
    void branch = openborvariant("current_branch");
 
    /*if(music != NULL()){

        //TEMPORARY SOLUTION UNTIL ALL SOR TRACKS ARE ADDED, IT WILL PLAY GG/SMS TRACKS ON SPECIFIC ORIGINAL LEVELS
        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 = "Musics/";}else{folder = "data/music/"+mStyle+"/";}
        if(openborvariant("in_level")){playmusic(folder+music, 1);}
    }*/

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

}

levels.txt for set 2 (third game mode) as a music play test:
Code:
set    Music_Play_Test
nosame    1
branch    Test1-1
file    data/levels/test1-1.txt
branch    Test1-2
file    data/levels/test1-2.txt

Still, the music doesn't play. Am I missing something? Should I use updated.c for this to play?
@maxman I'm a bit confused, why the musicPlaying() is inside the update.c? And in the SORX this is a global variable name, not a function.

1691710926946.png

According to the codes you posted, this is not how the original script works. To help you better I suggest defining more clearly what result you want to achieve and what problem you are having, depending on your goal we could develop a custom solution specifically for your problem without carrying the entire SORX code, some parts may not be necessary for your game.
 
I created musicPlaying() function name in update.c thinking it could call out the function from my own, but I didn't realize/notice there's a globalvar name called "musicPlaying" in the other file. I didn't take a look at it the first time I started to make it work. It was meant to be a function name, but I didn't know that same name exists as a varname.

I just changed the function name from musicPlaying to goStartDaMusic in update.c, just to avoid the name confusion (function name and varname).

BTW what's that musicPlay() function like?

According to the codes you posted, this is not how the original script works. To help you better I suggest defining more clearly what result you want to achieve and what problem you are having, depending on your goal we could develop a custom solution specifically for your problem without carrying the entire SORX code, some parts may not be necessary for your game.
OK. What I want to achieve is to have the music play straight from the music folder itself only instead of its sub-folders (red and blue folders). I will bother the sub-folders later. I just want to try out one music playlist from the music folder for now. In levels, musicoverlap 1 is set, which I forgot to input. (Mine is similar to mersox's goal.) The two test levels I have don't have music. For example, in stage 1-1, I want the music to start. In stage 1-2, that music will have to continue playing from stage 1-1. Then, when you quit game and go to load game to return to where you left off, you want the same music to play in the beginning of stage 1-2.

I'm having trouble with defining certain music to play in each level with musicoverlap 1 used in levels.txt. Even though I copied the exact scripts and modified them for my own, I can't get the music playing. I don't know how to make the right setup for it, so I'm stuck/lost.

I made changes this time, but still, no music is active. I don't have to share the full ones here, partial ones for now.

update.c:
C:
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());
            }
        }

    }

}

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

    if(mStyle == "custom"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}

    if(set == 2){
        // MUSIC TEST IN LEVELS
        stopMusic = "no"; //IF YOU DON'T WANT THE MUSIC TO COTINUE ALONG THE NEXT LEVELS, SIMPLY FILL "YES"

        if(stopMusic == "no"){ //THE "STOPMUSIC" OPTION IS "NO"?? ALL LEVELS BELOW WILL USE THE SAME MUSIC
            if(branch == "Test1-1"){
                music = "italy.bor";
                playmusic(folder+music, 1);
                setglobalvar("musicStopped", NULL());
            }
            if(branch == "Test1-2"){
                if(getglobalvar("musicStopped") != NULL()){
                    music = "italy.bor";
                    playmusic(folder+music, 1);
                    setglobalvar("musicStopped", NULL());
                }
            }
        }else if(stopMusic == "yes") //THE "STOPMUSIC" OPTION IS "YES"?? EACH LEVEL BELOW WILL USE THE DEFINED MUSIC
        {
            if(branch == "Test1-1"){ //DEFINE EACH MUSIC FOR EACH STAGE
                music = "italy.bor";
                playmusic(folder+music, 1);
            }
            if(branch == "Test1-2"){ //DEFINE EACH MUSIC FOR EACH STAGE
                music = "italy.bor";
                playmusic(folder+music, 1);
            }
        }
    }
}

musicmisc.c (musicReplay() is the only function name I have in this file):
C:
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(mStyle == "custom"){folder = "data/music/";}//else{folder = "data/music/"+mStyle+"/";}
        if(openborvariant("in_level")){playmusic(folder+music, 1);}

    }

    
}

levels.txt:
Code:
set    Music_Play_Test
nosame    1
musicoverlap 1
branch    Test1-1
file    data/levels/test1-1.txt
branch    Test1-2
file    data/levels/test1-2.txt

Whether I use else or not in musicmisc.c, it doesn't crash. Yet, the music isn't playing.
 
I created musicPlaying() function name in update.c thinking it could call out the function from my own, but I didn't realize/notice there's a globalvar name called "musicPlaying" in the other file. I didn't take a look at it the first time I started to make it work. It was meant to be a function name, but I didn't know that same name exists as a varname.

I just changed the function name from musicPlaying to goStartDaMusic in update.c, just to avoid the name confusion (function name and varname).

BTW what's that musicPlay() function like?


OK. What I want to achieve is to have the music play straight from the music folder itself only instead of its sub-folders (red and blue folders). I will bother the sub-folders later. I just want to try out one music playlist from the music folder for now. In levels, musicoverlap 1 is set, which I forgot to input. (Mine is similar to mersox's goal.) The two test levels I have don't have music. For example, in stage 1-1, I want the music to start. In stage 1-2, that music will have to continue playing from stage 1-1. Then, when you quit game and go to load game to return to where you left off, you want the same music to play in the beginning of stage 1-2.

I'm having trouble with defining certain music to play in each level with musicoverlap 1 used in levels.txt. Even though I copied the exact scripts and modified them for my own, I can't get the music playing. I don't know how to make the right setup for it, so I'm stuck/lost.

I made changes this time, but still, no music is active. I don't have to share the full ones here, partial ones for now.

update.c:
C:
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());
            }
        }

    }

}

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

    if(mStyle == "custom"){folder = "data/music/";}else{folder = "data/music/"+mStyle+"/";}

    if(set == 2){
        // MUSIC TEST IN LEVELS
        stopMusic = "no"; //IF YOU DON'T WANT THE MUSIC TO COTINUE ALONG THE NEXT LEVELS, SIMPLY FILL "YES"

        if(stopMusic == "no"){ //THE "STOPMUSIC" OPTION IS "NO"?? ALL LEVELS BELOW WILL USE THE SAME MUSIC
            if(branch == "Test1-1"){
                music = "italy.bor";
                playmusic(folder+music, 1);
                setglobalvar("musicStopped", NULL());
            }
            if(branch == "Test1-2"){
                if(getglobalvar("musicStopped") != NULL()){
                    music = "italy.bor";
                    playmusic(folder+music, 1);
                    setglobalvar("musicStopped", NULL());
                }
            }
        }else if(stopMusic == "yes") //THE "STOPMUSIC" OPTION IS "YES"?? EACH LEVEL BELOW WILL USE THE DEFINED MUSIC
        {
            if(branch == "Test1-1"){ //DEFINE EACH MUSIC FOR EACH STAGE
                music = "italy.bor";
                playmusic(folder+music, 1);
            }
            if(branch == "Test1-2"){ //DEFINE EACH MUSIC FOR EACH STAGE
                music = "italy.bor";
                playmusic(folder+music, 1);
            }
        }
    }
}

musicmisc.c (musicReplay() is the only function name I have in this file):
C:
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(mStyle == "custom"){folder = "data/music/";}//else{folder = "data/music/"+mStyle+"/";}
        if(openborvariant("in_level")){playmusic(folder+music, 1);}

    }

   
}

levels.txt:
Code:
set    Music_Play_Test
nosame    1
musicoverlap 1
branch    Test1-1
file    data/levels/test1-1.txt
branch    Test1-2
file    data/levels/test1-2.txt

Whether I use else or not in musicmisc.c, it doesn't crash. Yet, the music isn't playing.
@maxman
Let's make it work in parts. First, I will apply the scripted music code in a fresh BOR mod to simplify it, and after the music plays normally we can go to the next step, which is the replay.
As soon as I finish the BOR, I will post here for you.
 
@maxman Ok, here's the first step, playing musics with the script. Try to apply it in your game and when it works fine we can go to the next step, replaying musics.

Below the changed files:

Levels.txt
Code:
Timeloc    150 220 0 0 1
set        Lv1

branch    level1
z        180 230
file    data/levels/lv1.txt

branch    level2
z        180 230
file    data/levels/lv1.txt

branch    level3
z        180 230
file    data/levels/lv1.txt

branch    level4
z        180 230
file    data/levels/lv1.txt

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

void main()
{
    musicStage();
}

Musics.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;
   
    //LEVEL 1
    if(branch == "level1"){music = "02.ogg";    musicPlay(music, "root", 1);}

    //LEVEL 2
    if(branch == "level2"){music = "03.ogg";    musicPlay(music, "root", 1);}

    //LEVEL 3
    if(branch == "level3"){music = "04.ogg";    musicPlay(music, "root", 1);}

    //LEVEL 4
    if(branch == "level4"){music = "05.ogg";    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);

    //PLAY MUSIC
    fademusic(0);
    playmusic(folder+music, loop, offset);
}
 
Just tried it. At least it's okay. I like how we just got it started with music playing in script. However, after testing it, this is like the default BOR music setup, which you play music in the beginning and another music exists in the next stage (which I excluded the level 2 part because a certain music plays in level 2, which is nice by the way). You go back to Load Game and no music is playing. What I want is to play music like in your SOR2X and other commercial games with that kind.

Here's what I tried.
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;
    int stopMusic;
    void set    = openborvariant("current_set");

    if(set == 2){
        if(branch == "Test1-1"){music = "italy.bor";    musicPlay(music, "root", 1);} // LEVEL 1-1 / Level 1
        if(branch == "Test1-2"){music = "italy.bor";    musicPlay(music, "root", 1);} // LEVEL 1-2 / Level 2
    }
}

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);
}

It's not bad at all, but the music script setup for it needs to be changed like your SOR2X for playing previous music I use different stages in the levels. Thank you for your time, @Kratus. Looking forward to your new modified update, so we can go to the next step.
 
Just tried it. At least it's okay. I like how we just got it started with music playing in script. However, after testing it, this is like the default BOR music setup, which you play music in the beginning and another music exists in the next stage (which I excluded the level 2 part because a certain music plays in level 2, which is nice by the way). You go back to Load Game and no music is playing. What I want is to play music like in your SOR2X and other commercial games with that kind.
Like I said, we must go step by step and I haven't reached the part where the music continues yet. We can't add advanced features once even the basics are not working, in which the music does not play like you reported in previous posts.

It's not bad at all, but the music script setup for it needs to be changed like your SOR2X for playing previous music I use different stages in the levels. Thank you for your time, @Kratus. Looking forward to your new modified update, so we can go to the next step.
Yeah, I know it. First, confirm if the music is playing normally on the same way as the default BOR and then we can continue to the next step.
 
My apologies, sir. You are right. We are in a step-by-step process. Like I said, it's a very good start. The music is working well as it is. I think we can go to the next step, now that I got it started. I'm not gonna worry about the final outcome of it until we reach there.
 
Here goes the second step, music replaying.

First, note at the first seconds of the video, you will see the music replaying after I enter/quit the sound menu, this is to apply the new volume in case you change it, scripted musics needs this task.

Second, look how the music continues between levels 3 and 4 using the musicoverlap 1 at the levels.txt. So, if I quit and then load the level 4 again, the music will be replayed normally by the script. Don't forget to remove all the native music/bossmusic functions in your levels otherwise it can interfere in the scripted musics.


Levels.txt
Code:
Timeloc            150 220 0 0 1
set                Lv1
musicoverlap    1
cansave            2

branch    Level_1
z        180 230
file    data/levels/lv1.txt

branch    Level_2
z        180 230
file    data/levels/lv1.txt

branch    Level_3
z        180 230
file    data/levels/lv1.txt

branch    Level_4
z        180 230
file    data/levels/lv1.txt

branch    Level_5
z        180 230
file    data/levels/lv1.txt

Level file
Code:
background    data/bgs/lv1/back.gif 0.5 0 0 0 0 0 -1 1 0 0
panel        data/bgs/lv1/n01.gif    data/bgs/lv1/neon01.gif    data/bgs/lv1/s01.gif
panel        data/bgs/lv1/n02.gif    data/bgs/lv1/neon02.gif    data/bgs/lv1/s02.gif
panel        data/bgs/lv1/n03.gif    none                none
panel        data/bgs/lv1/n04.gif    none                none
panel        data/bgs/lv1/n05.gif    none                data/bgs/lv1/s05
panel        data/bgs/lv1/n06.gif    none                none
panel        data/bgs/lv1/n07.gif    none                none
panel        data/bgs/lv1/n05.gif    data/bgs/lv1/clubk        data/bgs/lv1/s05
frontpanel    data/bgs/lv1/f00.gif
frontpanel    data/bgs/lv1/f01.gif
frontpanel    data/bgs/lv1/f02.gif
frontpanel    data/bgs/lv1/f03.gif
order        fdefecdhfecggdab

group 100 100
at 0

spawn    Shermie
coords    600 230
at    0

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

void main()
{
    musicStage();
}

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(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());}
        }
    }

    //DRAW THE CURRENT BRANCH, ERASE IT AFTER ALL TESTS ARE DONE
    drawstring(0, 50, 0, openborvariant("current_branch"));
}

Musics.c
C:
void musicStage()
{//Play music in each stage
    void branch    = openborvariant("current_branch");
    void music;
    
    //LEVEL 1
    if(branch == "Level_1"){music = "01.ogg";    musicPlay(music, "root", 1);}

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

    //LEVELS 3-4
    //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 == "Level_3"){
        music = "03.ogg";
        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
    if(branch == "Level_4"){
        if(getglobalvar("musicStopped") != NULL()){
            music = "03.ogg";
            musicPlay(music, "root", 1);
            setglobalvar("musicStopped", NULL());
        }
    }

    //LEVEL 5
    if(branch == "Level_5"){music = "05.ogg";    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);

    //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);}
    }
}
 
Thank you very much! This works perfectly! 😌 I came to realize I missed and didn't bother using a few important ones including updated.c and musicPlay(). Well, it's all good. I got it working.

I'm really loving this result! 🥰
 
Last edited:
Back
Top Bottom