ACS: Changing sectors light level

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
Ahpiox
Posts: 98
Joined: Fri Dec 22, 2017 1:52 am

ACS: Changing sectors light level

Post by Ahpiox »

Code: Select all

#include "zcommon.acs"

script "LightRide" ENTER // addr = 8, flags=0000
{
    int local0;
    int goto_block;
    switch (goto_block) {
    case 0:
        if ((PlayerNumber() == 0)) {
            local0 = 0;
            goto_block = 2; restart;
        } else {
            goto_block = 3; restart;
        }

    case 2:
        if ((local0 < 9999)) {
			if(GetSectorLightLevel(local0) > 148) {Light_LowerByValue(local0, GetSectorLightLevel(local0) / 1.4);}
            Light_LowerByValue(local0, 24);
			SetFogDensity(local0,56);
            local0++;
            goto_block = 2; restart;
        } else {
            goto_block = 3; restart;
        }

    case 3:
        Terminate;

    }
}
It's modified code from DarkDoom. I tried to make this script seriously lowing light level if sector has light level higher than 148 units. But as i can see, this is not work at all. Any help pls?
User avatar
KeksDose
 
 
Posts: 596
Joined: Thu Jul 05, 2007 6:13 pm
Location: my laboratory

Re: ACS: Changing sectors light level

Post by KeksDose »

At a glance, this bit here doesn't look good:

Code: Select all

Light_LowerByValue(local0, GetSectorLightLevel(local0) / 1.4); 
In acs, '.' is special notation for fixed point. The gist lies in interpretation, as 1.0 fixed = 65536 whole. Here, 1.4 is around 100k, so the division results in 0, as it's done whole.

You can divide fixed by a whole number, and you can also multiply fixed with a whole number, and get the expected fixed result. [wiki]FixedMul[/wiki] and [wiki]FixedDiv[/wiki] will handle anything involving two fixed numbers.

I'd do this:

Code: Select all

(GetSectorLightLevel(local0) * 10) / 14
User avatar
Ahpiox
Posts: 98
Joined: Fri Dec 22, 2017 1:52 am

Re: ACS: Changing sectors light level

Post by Ahpiox »

Nope, still nothing. Idk why, but still thanks for reply
User avatar
KeksDose
 
 
Posts: 596
Joined: Thu Jul 05, 2007 6:13 pm
Location: my laboratory

Re: ACS: Changing sectors light level

Post by KeksDose »

Scratch everything. This script will not work as expected, because you are cycling through sector tags, not every sector by itself, so GetSectorLightLevel will, for same tagged sectors, return one light value for all of them, even if they're different. Think of a map with only tag 0 and light level 255, except for one sector, which happens to be the one picked by GetSectorLightLevel.

This should definitely be done in zscript, since you can then actually cycle through each sector individually.
User avatar
Ahpiox
Posts: 98
Joined: Fri Dec 22, 2017 1:52 am

Re: ACS: Changing sectors light level

Post by Ahpiox »

Okay, will try to make this thing in zscript. Will learn from wiki and DarkDoomZ script. Thanks

Return to “Scripting”