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.

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
Enjay
 
 
Posts: 26517
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

ACS Choose 1, 2 or 3 sectors ?

Post by Enjay »

I currently have this in an ACS script:

Code: Select all

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
Caligari87
Admin
Posts: 6174
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: ACS Choose 1, 2 or 3 sectors ?

Post by Caligari87 »

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 all

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
Enjay
 
 
Posts: 26517
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: ACS Choose 1, 2 or 3 sectors ?

Post by Enjay »

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 all

	WhichLight=17;

	while(WhichLight <20)
	{
	    ChangeCeiling(WhichLight, "NJF002");
		Light_ChangeToValue(WhichLight, 144);
		Thing_Activate(WhichLight);
		WhichLight++;
	}
Is that suitable?
Post Reply

Return to “Scripting”