CallACS with result on SwitchableDecoration

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.

CallACS with result on SwitchableDecoration

Postby Officer D » Sat Mar 27, 2021 12:53 pm

I'm trying to have a switchable actor's Active state, do a ACS player inventory check with result.
I'm guessing the player is not being set as activator, hence why its returning 1. I tried SetActivator(0, AAPTR_PLAYER1); instead of SetActivatorToTarget(0); but the problem remained. Any ideas on what is going on here?

Decorate:
Code: Select allExpand view
actor LootBox : SwitchableDecoration
{
  health 150
  radius 16
  height 28
  scale 0.5
  Activation THINGSPEC_Activate
  +USESPECIAL
  +CANNOTPUSH
  +SHOOTABLE
  +NOBLOOD
  States
  {
  Spawn:
   *irrelevant code*
   loop
  Active:
   VOXB A 1 A_JumpIf(CallACS("KeyCheck",0,0,0) == 0,"OpenBox")
   VOXB A 0 A_JumpIf(CallACS("KeyCheck",0,0,0) == 1,"NoKey")
   Stop
  NoKey:
   VOXB A 1 A_SpawnItem("Lootbox")
   VOXB A 1 A_Print("Key Required",3,"BIGFONT")
   Stop
  OpenBox:
   VOXB A 1 A_SpawnItem("LootboxOpen")
   TNT1 A 0 A_PlaySound("chest/open", 0, 1.0, FALSE, 1.3)
   Stop
  Death:
   *irrelevant code*
    stop
  }
}

Image

ACS:
Code: Select allExpand view
Script "KeyCheck" (void)
{
   SetActivatorToTarget(0);
   Delay(1);
   if(CheckInventory("ModdedBlueCard") || CheckInventory("ModdedRedCard")
    || CheckInventory("ModdedYellowCard") || CheckInventory("ModdedRedSkull")
     || CheckInventory("ModdedBlueSkull") || CheckInventory("ModdedYellowSkull"))
      {
         SetResultValue(0);
         terminate;
      }
      else
      {
         SetResultValue(1);
         terminate;
      }
}
User avatar
Officer D
 
Joined: 10 May 2019
Location: Germany
Discord: https://discord.gg/jr7yCvY
Twitch ID: www.twitch.tv/officer_d82
Operating System: Windows 10/8.1/8/201x 64-bit
Graphics Processor: nVidia with Vulkan support

Re: CallACS with result on SwitchableDecoration

Postby Mikk- » Sat Mar 27, 2021 12:59 pm

You can use THINGSPEC_ThingTargets on on the Activation properties - that should hopefully solve your issue. You can use multiple THINGSPEC_* flags by using the | separator.

https://zdoom.org/wiki/Actor_properties#Activation
User avatar
Mikk-
yooooooooooo
 
Joined: 30 Jun 2009
Location: Somewhere off Kanagawa
Discord: Mikk0451#3922

Re: CallACS with result on SwitchableDecoration

Postby Officer D » Sat Mar 27, 2021 1:10 pm

The result value is still 1 it would seem. The pint message "Key Required" just keeps on showing.

Code: Select allExpand view
Activation THINGSPEC_Activate | THINGSPEC_ThingTargets

Didn't change much unfortunately.
User avatar
Officer D
 
Joined: 10 May 2019
Location: Germany
Discord: https://discord.gg/jr7yCvY
Twitch ID: www.twitch.tv/officer_d82
Operating System: Windows 10/8.1/8/201x 64-bit
Graphics Processor: nVidia with Vulkan support

Re: CallACS with result on SwitchableDecoration

Postby Mikk- » Sat Mar 27, 2021 1:19 pm

Hm.. with some testing I managed to get it to work by removing the delay from the ACS script.
User avatar
Mikk-
yooooooooooo
 
Joined: 30 Jun 2009
Location: Somewhere off Kanagawa
Discord: Mikk0451#3922

Re: CallACS with result on SwitchableDecoration

Postby Officer D » Sat Mar 27, 2021 1:22 pm

Wtf! :| That indeed fixed the problem. Although it makes no sense at all. Thank you for your help!
User avatar
Officer D
 
Joined: 10 May 2019
Location: Germany
Discord: https://discord.gg/jr7yCvY
Twitch ID: www.twitch.tv/officer_d82
Operating System: Windows 10/8.1/8/201x 64-bit
Graphics Processor: nVidia with Vulkan support

Re: CallACS with result on SwitchableDecoration

Postby Simon Bollerbeck » Sat Mar 27, 2021 8:59 pm

[quote="Officer D"]Although it makes no sense at all.[/quote]
Read this: https://zdoom.org/wiki/SetResultValue
Simon Bollerbeck
 

Re: CallACS with result on SwitchableDecoration

Postby Gez » Sun Mar 28, 2021 3:24 am

Yes, this is because the DECORATE code wants a result in the same tic it runs the script, it will not wait for the script if there is a delay. By default, the return value is 1, to show that the script was successfully launched. So what happens is that the DECORATE code starts the script, the ACS code hits a delay and so returns the value 1 because it knows it needs to send a return value ASAP, the DECORATE code runs with the result of that return, on the next tic the ACS code runs the rest of the script and sets a return value but it's too late by then.
Gez
 
 
 
Joined: 06 Jul 2007


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests