ACS Choose 1, 2 or 3 sectors ?

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.

ACS Choose 1, 2 or 3 sectors ?

Postby Enjay » Tue Jan 05, 2021 10:48 am

I currently have this in an ACS script:

Code: Select allExpand view
int WhichLight;
script 26 OPEN
{
   WhichLight = (random(17,19));

   ChangeCeiling(WhichLight, "NJF002B");
   Light_ChangeToValue(WhichLight, 112);
   Thing_Deactivate(WhichLight);

   delay(random(4, 16));

   ChangeCeiling(WhichLight, "NJF002");
   Light_ChangeToValue(WhichLight, 144);
   Thing_Activate(WhichLight);

   delay(random(2,24));

   restart;
}


That picks a random number from 17 to 19 (which corresponds to a sector tag and dynamic light) and then makes changes in that sector to make it look like the light has failed temporarily before starting again with a new random choice. It works, but it means that only one light fails at a time.

I'd like to make it so that each time the script runs, any of the sectors (and dynamic lights) could fail in any combination from only one light (as it is now) through any two of the lights and right up to all three. I can do it very mechanically by lots of copy/paste code, but I'm sure that there must be a more efficient way of doing it. Can anyone help out and show me how?
User avatar
Enjay
Everyone is a moon, and has a dark side which he never shows to anybody. Twain
 
 
 
Joined: 15 Jul 2003
Location: Scotland

Re: ACS Choose 1, 2 or 3 sectors ?

Postby Caligari87 » Tue Jan 05, 2021 2:08 pm

I think a for loop over your lights with a random chance for each light to fail, perhaps?

My ACS is extremely rusty so this probably will need correcting, but here's what I'm thinking.
Code: Select allExpand view
script 26 OPEN
{
   //Randomly fail some lights of the set
   for (int WhichLight=17; WhichLight<=19; WhichLight++) {
      if (random(0,100) <= 50) {
         ChangeCeiling(WhichLight, "NJF002B");
         Light_ChangeToValue(WhichLight, 112);
         Thing_Deactivate(WhichLight);
      }
   }

   delay(random(4, 16));

   // Relight all lights regardless of if they failed or not
   for (int WhichLight=17; WhichLight<=19; WhichLight++) {
      ChangeCeiling(WhichLight, "NJF002");
      Light_ChangeToValue(WhichLight, 144);
      Thing_Activate(WhichLight);
   }

   delay(random(2,24));

   restart;
}


8-)
User avatar
Caligari87
I'm just here for the community
User Accounts Assistant
 
Joined: 26 Feb 2004
Location: Salt Lake City, Utah, USA
Discord: Caligari87#3089

Re: ACS Choose 1, 2 or 3 sectors ?

Postby Enjay » Tue Jan 05, 2021 3:20 pm

Aha! Thank you. I don't quite follow how the for loop is doing its thing, but it is doing it. Basically, I'm missing a bit of knowledge about how the syntax works, so I can't unpick the sense of it.

Also, the compiler didn't like the second instance of: for (int WhichLight=17; WhichLight<=19; WhichLight++) {
"WhichLight: Redefined Identifier"
but I think that I can work around that. Thank you. :)


[edit]
Using this instead of the second for seems to work:

Code: Select allExpand view
   WhichLight=17;

   while(WhichLight <20)
   {
       ChangeCeiling(WhichLight, "NJF002");
      Light_ChangeToValue(WhichLight, 144);
      Thing_Activate(WhichLight);
      WhichLight++;
   }

Is that suitable?
User avatar
Enjay
Everyone is a moon, and has a dark side which he never shows to anybody. Twain
 
 
 
Joined: 15 Jul 2003
Location: Scotland


Return to Scripting

Who is online

Users browsing this forum: Player701 and 2 guests