Acs Script won't run. (Changing music)

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!)
Post Reply
User avatar
Hor1zon Str1der
Posts: 21
Joined: Sat Aug 21, 2021 9:09 am
Location: forgotten in space.

Acs Script won't run. (Changing music)

Post by Hor1zon Str1der »

I'm trying to make a crude music shuffler, but when the game starts, the script doesn't run. I've even tried executing it with a line, and nothing. Help please?
Spoiler:
User avatar
Virathas
Posts: 254
Joined: Thu Aug 10, 2017 9:38 am

Re: Acs Script won't run. (Changing music)

Post by Virathas »

If this is all the code, it's not surprising - Scripts 2 to 4 have no way to be executed, since they need to be activated manually.
I am not sure how this is exactly supposed to work in your case, but i believe this would suffice:

Code: Select all

#INCLUDE "Zcommon.acs"

int TrackNum;

script "Music" enter
{
TrackNum = random(1,3);
while (1)
{
   if (TrackNum == 1)
   {
      SetMusic ("VAN1");
      Delay(8400);
      TrackNum = random(1,3);
   }
   if (TrackNum == 2)
   {
      SetMusic ("VAN2");
      Delay(8400);
      TrackNum = random(1,3);
   }
   if (TrackNum == 3)
   {
      SetMusic ("VAN3");
      Delay(8400);
      TrackNum = random(1,3);
   }
}
}
(Untested) This will select one of the files on map start, and after the delay, will choose again. This is probably not the best or cleanest ways, but it should do what you want. :)

PS: Avoid using numbered scripts if possible, that is an easy way to break compatibility in surprising ways. Instead, use named scripts.
User avatar
Hor1zon Str1der
Posts: 21
Joined: Sat Aug 21, 2021 9:09 am
Location: forgotten in space.

Re: Acs Script won't run. (Changing music)

Post by Hor1zon Str1der »

That works. Thanks. I feel like I should've know what the problem was. :P And I will keep naming scripts in mind.
User avatar
MFG38
Posts: 414
Joined: Sun Apr 14, 2019 8:26 am
Graphics Processor: nVidia (Modern GZDoom)
Location: Finland
Contact:

Re: Acs Script won't run. (Changing music)

Post by MFG38 »

You can truncate your code a tiny bit by shoving all of the if statements into a single switch/case statement, like so:

Code: Select all

#INCLUDE "Zcommon.acs"

int TrackNum;

script "Music" enter
{
TrackNum = random(1,3);
str trackName;
while (1)
{
   switch(TrackNum)
   {
      case 1:
         trackName = "VAN1";
         break;
      case 2:
         trackName = "VAN2";
         break;
      case 3:
         trackName = "VAN3";
         break;
      }

      SetMusic(trackName);
      Delay(8400);
      TrackNum = random(1,3);
   }
}
}
User avatar
Hor1zon Str1der
Posts: 21
Joined: Sat Aug 21, 2021 9:09 am
Location: forgotten in space.

Re: Acs Script won't run. (Changing music)

Post by Hor1zon Str1der »

MFG38, Is it possible to add individual delays to the cases?
User avatar
MFG38
Posts: 414
Joined: Sun Apr 14, 2019 8:26 am
Graphics Processor: nVidia (Modern GZDoom)
Location: Finland
Contact:

Re: Acs Script won't run. (Changing music)

Post by MFG38 »

Hor1zon Str1der wrote:MFG38, Is it possible to add individual delays to the cases?
It should be to my knowledge.
Post Reply

Return to “Scripting”