Fading from one sector color to another through script?

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!)
User avatar
Tormentor667
Posts: 13534
Joined: Wed Jul 16, 2003 3:52 am

Fading from one sector color to another through script?

Post by Tormentor667 »

Let's say a sector has colored lights through an ACS script (or UDM) like this:

Code: Select all

Sector_SetColor(sectortag, 255, 160, 64);
and I want this sector to be faded into any other kind of colored sector light in a specific amount of time through an acs script, how would I do that, for example to this color (or any other color)?

Code: Select all

Sector_SetColor(sectortag, 160, 32, 16);
User avatar
Rachael
Posts: 13635
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her

Re: Fading from one sector color to another through script?

Post by Rachael »

This is kind of pseudo-code but you should be able to get the idea... sorry for the messiness of it I haven't coded in ACS for 8 years.

Code: Select all

int red1 = 255;
int green1 = 160;
int blue1 = 64;

int red2 = 160;
int green2 = 32;
int blue2 = 16;

int fadetime = 350; // length of time (350 is 10 seconds)

for (int i = 0; i < fadetime; i++)
{
	int red = (red1 * (fadetime - i) + red2 * i) / fadetime;
	int green = (green1 * (fadetime - i) + green2 * i) / fadetime;
	int blue = (blue1 * (fadetime - i) + blue2 * i) / fadetime;

	Sector_SetColor(sectortag, red, green, blue);
	delay(1);
}
Hopefully, someone can correct me if I got any of the ACS-specific language mechanics wrong. I wrote this in C, hoping it will work in ACS without modification. As I've said - it's been 8 years since I've used ACS.
User avatar
Guardsoul
Posts: 195
Joined: Sun Dec 11, 2011 3:58 am
Location: Creating a new dimension

Re: Fading from one sector color to another through script?

Post by Guardsoul »

Rachael wrote:This is kind of pseudo-code but you should be able to get the idea... sorry for the messiness of it I haven't coded in ACS for 8 years.

Code: Select all

int red1 = 255;
int green1 = 160;
int blue1 = 64;

int red2 = 160;
int green2 = 32;
int blue2 = 16;

int fadetime = 350; // length of time (350 is 10 seconds)

for (int i = 0; i < fadetime; i++)
{
	int red = (red1 * (fadetime - i) + red2 * i) / fadetime;
	int green = (green1 * (fadetime - i) + green2 * i) / fadetime;
	int blue = (blue1 * (fadetime - i) + blue2 * i) / fadetime;

	Sector_SetColor(sectortag, red, green, blue);
	delay(1);
}
Hopefully, someone can correct me if I got any of the ACS-specific language mechanics wrong. I wrote this in C, hoping it will work in ACS without modification. As I've said - it's been 8 years since I've used ACS.
Everything is fine in that script and works as intended.
User avatar
Rachael
Posts: 13635
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her

Re: Fading from one sector color to another through script?

Post by Rachael »

Thank you. :)
User avatar
Tormentor667
Posts: 13534
Joined: Wed Jul 16, 2003 3:52 am

Re: Fading from one sector color to another through script?

Post by Tormentor667 »

Thanks, that already works very well. Now imagine we have only the goal color of the sector but not the source color of the sector, how would I have to change the script accordingly?
User avatar
Rachael
Posts: 13635
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her

Re: Fading from one sector color to another through script?

Post by Rachael »

I don't think this can be done without ZScript because that requires accessing individual sectors which cannot be done in ACS as far as I know.
User avatar
Tormentor667
Posts: 13534
Joined: Wed Jul 16, 2003 3:52 am

Re: Fading from one sector color to another through script?

Post by Tormentor667 »

Okay, then I will just go with your script :) Thnaks kindly Rachael!
User avatar
Rachael
Posts: 13635
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her

Re: Fading from one sector color to another through script?

Post by Rachael »

Sure thing. :)
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Fading from one sector color to another through script?

Post by Apeirogon »

Why dont get current sector color in RGB and then check if R/G/B_current_sector < R/G/B_desired_sector_color add +1 to R/G/B_current_sector, if not -1 to R/G/B_current_sector?
Or problem is how get current sector color?

Return to “Scripting”