Acs Script won't run. (Changing music)

Tue Nov 02, 2021 11:54 pm

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:

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

Wed Nov 03, 2021 12:14 am

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:
#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.

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

Wed Nov 03, 2021 7:43 am

That works. Thanks. I feel like I should've know what the problem was. :P And I will keep naming scripts in mind.

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

Wed Nov 03, 2021 8:16 am

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

Code:
#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);
   }
}
}

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

Wed Nov 03, 2021 10:56 am

MFG38, Is it possible to add individual delays to the cases?

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

Wed Nov 03, 2021 12:12 pm

Hor1zon Str1der wrote:MFG38, Is it possible to add individual delays to the cases?


It should be to my knowledge.