Page 1 of 1

Acs Script won't run. (Changing music)

Posted: Tue Nov 02, 2021 11:54 pm
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:

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

Posted: Wed Nov 03, 2021 12:14 am
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.

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

Posted: Wed Nov 03, 2021 7:43 am
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.

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

Posted: Wed Nov 03, 2021 8:16 am
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);
   }
}
}

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

Posted: Wed Nov 03, 2021 10:56 am
by Hor1zon Str1der
MFG38, Is it possible to add individual delays to the cases?

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

Posted: Wed Nov 03, 2021 12:12 pm
by MFG38
Hor1zon Str1der wrote:MFG38, Is it possible to add individual delays to the cases?
It should be to my knowledge.