Music change between rooms that only activate until a certain point

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
AshHouswares
Posts: 86
Joined: Fri Jun 03, 2022 11:31 am
Graphics Processor: Not Listed

Music change between rooms that only activate until a certain point

Post by AshHouswares »

I need a little help with an "if" script of sorts. In this game, the music changes depending on which part of the map you are on. This is done with repeatable scripts, allowing for the music to change back and forth as you cross between locations.

However, near the end of the game a script is written to display a cutscene which also changes the music. This music change is supposed to overwrite all the previous scripts, meaning they those previous ones will no longer work after this event is triggered, keeping the final music change active up until the point where a "fifth" music change happens.

Code: Select all

//MUSIC CHANGERS
script 31 (void)
{
	SetMusic("HFCIRC01"); //Lost In Darkness
}

script 32 (void)
{
	SetMusic("HFCIRC02"); //Face Your Fears
}

script 33 (void)
{
	SetMusic("HFCIRC03"); //Investigation
}
These are the scripts used around the map to change music between locations. HOWEVER.

At the end of the main area, this event happens (a cut scene) that also changes music. So for example:

Code: Select all

script 131
{
       SetMusic("HFCIRC05"); //Possession
}
When that SCRIPT 131 happens, I want that to make all three previous scripts invalid so the music no longer changes to anything else once HFCIRC05 activates. I need some sort of "if" script to do this but not entirely sure how I should format it (as to not mess up all the work that has been done up until this point).

Any help is much appreciated.
Gez
 
 
Posts: 17750
Joined: Fri Jul 06, 2007 3:22 pm

Re: Music change between rooms that only activate until a certain point

Post by Gez »

You just need a map variable.

Code: Select all

//MUSIC CHANGERS
bool musicLock = false;

script 31 (void)
{
	if (!musicLock)	SetMusic("HFCIRC01"); //Lost In Darkness
}

script 32 (void)
{
	if (!musicLock)	SetMusic("HFCIRC02"); //Face Your Fears
}

script 33 (void)
{
	if (!musicLock)	SetMusic("HFCIRC03"); //Investigation
}

script 131
{
	musicLock = true;
	SetMusic("HFCIRC05"); //Possession
}
User avatar
AshHouswares
Posts: 86
Joined: Fri Jun 03, 2022 11:31 am
Graphics Processor: Not Listed

Re: Music change between rooms that only activate until a certain point

Post by AshHouswares »

Gez wrote: Sun Feb 05, 2023 12:56 am You just need a map variable.

Code: Select all

//MUSIC CHANGERS
bool musicLock = false;

script 31 (void)
{
	if (!musicLock)	SetMusic("HFCIRC01"); //Lost In Darkness
}

script 32 (void)
{
	if (!musicLock)	SetMusic("HFCIRC02"); //Face Your Fears
}

script 33 (void)
{
	if (!musicLock)	SetMusic("HFCIRC03"); //Investigation
}

script 131
{
	musicLock = true;
	SetMusic("HFCIRC05"); //Possession
}
That is perfection. Thank you so much.

Return to “Scripting”