[SOLVED]Actor Variable Not Decreasing on Death

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!)
Kan3x
Posts: 6
Joined: Tue Nov 08, 2022 4:19 pm

[SOLVED]Actor Variable Not Decreasing on Death

Post by Kan3x »

Hello.

So I'm trying to make a monster that can spawn a shield and I'd like to make him re-activate the shield only when the previous has been broken or it's expired.
My first thought was to count how many shield actors are "alive" and when there are 0 of them, the monster would be able to activate again the shield, but I cannot find any way to have something similar to "ThingCountName" in ZSCRIPT, so I tried to use a int variable.
I set the variable in the monster class
Spoiler:
then I gave the variable a value in the shield activation state and spawn the "shield spawner", setting the monster as the "projectile" target (value of 32 cause it will spawn 32 shield parts).
Spoiler:
So I have the Spawner spawing the actual shields and lastly I (try to) cast the variable on those and decrease the value by one on death.
Spoiler:
But this is not working properly and I don't really know why. For now, the variable lowers only when the shields disappear by themselves (the shield "dies" after 30 seconds) or only some times when I actually "kill" them and I cannot understand why of that "some times" :/

At first I simply didn't check for the existence of "w" and just did this:
Spoiler:
and it worked, initially, perfectly fine, then I tweaked a monster state (not connected with the variables or anything else) and now every time a shield dies, GZDoom crashes (VM execution aborted: tried to read from address zero).

I know I'm missing something obvious or I did something wrong in the process, but can some of you help me before I just go for acs? Thank you.

Here's the entirety of the code if needed:
ZSCRIPT.txt
You do not have the required permissions to view the files attached to this post.
Last edited by Kan3x on Wed Nov 09, 2022 4:56 pm, edited 1 time in total.
User avatar
Dan_The_Noob
Posts: 632
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support

Re: Actor Variable Not Decreasing on Death

Post by Dan_The_Noob »

master-child setup of some kind maybe?
Kan3x
Posts: 6
Joined: Tue Nov 08, 2022 4:19 pm

Re: Actor Variable Not Decreasing on Death

Post by Kan3x »

Dan_The_Noob wrote: Tue Nov 08, 2022 6:19 pm master-child setup of some kind maybe?
And that apparently just solved the issue, thank you! Still, I cannot find any explanation of why it does not work with the target pointer since both shield spawner and shield are projectiles... :/

Have you any tip about my second question?
I tested with A_CheckLOF with CLOFF_JUMPOBJECT and CLOFF_SKIPTARGET, so that (in theory) should return true when the virtual hitscan hits the shield and false when the shield is not between the monster and his target, but still it doesn't work.
User avatar
Dan_The_Noob
Posts: 632
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support

Re: Actor Variable Not Decreasing on Death

Post by Dan_The_Noob »

Kan3x wrote: Wed Nov 09, 2022 7:15 am
Dan_The_Noob wrote: Tue Nov 08, 2022 6:19 pm master-child setup of some kind maybe?
And that apparently just solved the issue, thank you! Still, I cannot find any explanation of why it does not work with the target pointer since both shield spawner and shield are projectiles... :/

Have you any tip about my second question?
I tested with A_CheckLOF with CLOFF_JUMPOBJECT and CLOFF_SKIPTARGET, so that (in theory) should return true when the virtual hitscan hits the shield and false when the shield is not between the monster and his target, but still it doesn't work.
not too sure on that one, hopefully someone else a bit better with functions can help you there.
Kan3x
Posts: 6
Joined: Tue Nov 08, 2022 4:19 pm

Re: Actor Variable Not Decreasing on Death

Post by Kan3x »

Dan_The_Noob wrote: Wed Nov 09, 2022 8:19 am not too sure on that one, hopefully someone else a bit better with functions can help you there.
I see, thank you anyway, I might make a new post and set this to solved

Return to “Scripting”