Return value is always null?

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.

Return value is always null?

Postby WARCHILD_89 » Wed Dec 30, 2020 11:38 pm

Hey guys.

I encountered a problem I cannot solve:

I have a line with the "Activate Script" action set. It enters the script and checks if all light actors with same TID are dormant. If true, activate the lights.

If false, deactivate the lights and make them dormant again.


The only problem is that no matter if the dormant flag is set or not (in doombuilder), the return value is always false. So I actually never get to activate the lights.




script "lightswitch" (int light) //So I can use any switch with ID for any light with corresponding ID to switch on
{
active = GetActorProperty(light,APROP_Dormant);

switch (active)
{
case TRUE: Thing_Activate(light);

case FALSE: Thing_Deactivate(light);
break;

}

}
User avatar
WARCHILD_89
DOOM NEMESIS / 3D MODELS / RESOURCE BACKUPS
 
Joined: 17 Nov 2013
Location: MIA between doomed dimensions

Re: Return value is always null?

Postby Player701 » Thu Dec 31, 2020 2:15 am

WARCHILD_89 wrote:checks if all light actors with same TID are dormant.

First, please note that GetActorProperty only checks a single actor. If you have multiple actors with the same TID, only one of them will be picked. However, if you activate and deactivate your lights simultaneously, this shouldn't be a problem.

The real problem is that you're missing a break statement after Thing_Activate. Therefore, after Thing_Activate has been called, control falls through to "case FALSE:", and Thing_Deactivate is then called immediately afterwards. Essentially, what's happening here is that your lights get activated and are then instantly deactivated, so you can't see them at all.

In your case, a switch statement is probably unnecessary. I'd rewrite the script as follows:

Code: Select allExpand view
script "lightswitch" (int light)
{
    if (GetActorProperty(light, APROP_Dormant))
    {
        Thing_Activate(light);
    }
    else
    {
        Thing_Deactivate(light);
    }
}
User avatar
Player701
 
 
 
Joined: 13 May 2009
Location: Russia
Discord: Player701#8214
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Return value is always null?

Postby WARCHILD_89 » Tue Jan 05, 2021 8:12 pm

Player701 wrote:
WARCHILD_89 wrote:checks if all light actors with same TID are dormant.

First, please note that GetActorProperty only checks a single actor. If you have multiple actors with the same TID, only one of them will be picked. However, if you activate and deactivate your lights simultaneously, this shouldn't be a problem.

The real problem is that you're missing a break statement after Thing_Activate. Therefore, after Thing_Activate has been called, control falls through to "case FALSE:", and Thing_Deactivate is then called immediately afterwards. Essentially, what's happening here is that your lights get activated and are then instantly deactivated, so you can't see them at all.

In your case, a switch statement is probably unnecessary. I'd rewrite the script as follows:

Code: Select allExpand view
script "lightswitch" (int light)
{
    if (GetActorProperty(light, APROP_Dormant))
    {
        Thing_Activate(light);
    }
    else
    {
        Thing_Deactivate(light);
    }
}



Thanks for the advice. My script is working, the missing break was accidentially. Your script is way more elegant though.

Despite that the problem was NOT the script. It was the sound actor.


My lights are working this way:

- one 3d model of a light
- one 3d model of a light cone
- one dynamic light and/or one spotlight
- an actor that plays a sound.

The sound actor does somehow corrupt the script and forces it to be always false.


the strange thing about it is, that I have a corridor where everything works just fine together with the sound actor. As soon as I copy that actor to place it again. The whole script does not work anymore. To me this doesn´t make any sense.


Imagine having a dormant monster. You activate it via script and it attacks you.

Now you place another 5 dormant monsters.

As soon as you activate the script, nothing happens. They all remain dormant.

This does not make any sense but that exactly my problem with this light actor.
User avatar
WARCHILD_89
DOOM NEMESIS / 3D MODELS / RESOURCE BACKUPS
 
Joined: 17 Nov 2013
Location: MIA between doomed dimensions

Re: Return value is always null?

Postby Player701 » Wed Jan 06, 2021 12:54 am

I'm sorry, but I'm not sure if I understand - do you still have this problem? If you do, could you please make a small test map to demonstrate it? I'm afraid I won't be able to tell you much without a test map in this case.
User avatar
Player701
 
 
 
Joined: 13 May 2009
Location: Russia
Discord: Player701#8214
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Return value is always null?

Postby WARCHILD_89 » Wed Jan 06, 2021 4:15 pm

Player701 wrote:I'm sorry, but I'm not sure if I understand - do you still have this problem? If you do, could you please make a small test map to demonstrate it? I'm afraid I won't be able to tell you much without a test map in this case.



The sound actor was acting weird with no logical explanation. I found out that my wad file was corrupted.

This happens sometimes when saving. The solution is to cut all decorate code, delete the endtry and create a new one. Then I paste the code again and it all works.

This "kind of" bug while using doombuilder and slade simultaniously really drives me nuts.

Anyway... case closed, thanks for your help!
User avatar
WARCHILD_89
DOOM NEMESIS / 3D MODELS / RESOURCE BACKUPS
 
Joined: 17 Nov 2013
Location: MIA between doomed dimensions


Return to Scripting

Who is online

Users browsing this forum: No registered users and 4 guests