Problem with A_SpawnItemEx and flags

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
Enjay
 
 
Posts: 26874
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Problem with A_SpawnItemEx and flags

Post by Enjay »

I've been working on modified version of the Hexen Demons and come across a minor problem.

In the extreme death, I am using this:

Code: Select all

DEM3 J 0 { A_SpawnItemEx("NJDemon3Chunk1", 0,0,45, 1+(random[DemonChunks](0,255)*0.015625), 1+(random[DemonChunks](0,255)*0.015625), NJDemon3ChunkFlags, 90);
	   A_SpawnItemEx("NJDemon3Chunk2", 0,0,45, 1+(random[DemonChunks](0,255)*0.015625), 1+(random[DemonChunks](0,255)*0.015625), NJDemon3ChunkFlags, 270);
	   A_SpawnItemEx("NJDemon3Chunk3", 0,0,45, 1+(random[DemonChunks](0,255)*0.015625), 1+(random[DemonChunks](0,255)*0.015625), NJDemon3ChunkFlags, 270);
	   A_SpawnItemEx("NJDemon3Chunk4", 0,0,45, 1+(random[DemonChunks](0,255)*0.015625), 1+(random[DemonChunks](0,255)*0.015625), NJDemon3ChunkFlags, 270);
	   A_SpawnItemEx("NJDemon3Chunk5", 0,0,45, 1+(random[DemonChunks](0,255)*0.015625), 1+(random[DemonChunks](0,255)*0.015625), NJDemon3ChunkFlags, 270);
	  }
and earlier I decalare:

Code: Select all

const NJDemon3ChunkFlags = SXF_TRANSFERTRANSLATION | SXF_ABSOLUTEVELOCITY;
the NJDemonChunksX actors are very similar to the original actors from Hexen.

All good. Just like the original demons, this results in a nice spray of body bits as the demon goes through its extreme death.

However, as soon as I add another flag to NJDemon3ChunkFlags, things stop working properly. Specifically, I wanted to add SXF_TRANSFERSCALE, but I've tried several other flags and had the same problem. The demon bits still spawn, but instead of being a spray of bits flying in several directions, they just spawn as a clump. (Perhaps this means that SXF_ABSOLUTEVELOCITY is being ignored?) any ideas?

It doesn't matter if I use the declared constant, or if I apply the flags directly in the state - same result.

Bonus question 1: Even if I only use the SXF_TRANSFERSCALE flag and no others, the chunks don't seem to scale. Is this not a suitable use case?

I can work around all this by just cloning the chunk actors and scaling them in their default state - but that can't take account of dynamic scaling - which I was going to add later.

Bonus question 2: in the A_SpawnItemEx code above (which I just copied and repurposed from *somewhere* (it's not the same as the default demon actors - so I don't know where it came from - maybe an older version?) after the word "random" there is a bit that says [DemonChunks]. What's the purpose of that? The code seems to work equally well with or without it.

User avatar
Enjay
 
 
Posts: 26874
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: Problem with A_SpawnItemEx and flags

Post by Enjay »

Well, I've got it sorted. I have no idea why, but if I use pretty much any other way of writing out the A_SpawnItemEx lines - including a copy of the stuff currently in gzdoom.pk3 I can use additional flags (including SXF_TRANSFERSCALE) and it works.

I can't see what's wrong with the above code, but I now have code that works. :shrug:
Blue Shadow
Posts: 5039
Joined: Sun Nov 14, 2010 12:59 am

Re: Problem with A_SpawnItemEx and flags

Post by Blue Shadow »

What's wrong here is that you're passing the flag/constant to the z velocity parameter. The flags parameter comes after the z velocity and angle parameters.

Enjay wrote: Mon Mar 17, 2025 5:03 amBonus question 2: in the A_SpawnItemEx code above (which I just copied and repurposed from *somewhere* (it's not the same as the default demon actors - so I don't know where it came from - maybe an older version?) after the word "random" there is a bit that says [DemonChunks]. What's the purpose of that? The code seems to work equally well with or without it.
The wiki says:
identifier is optional. Calls to a random function with an identifier do not interfere with the RNG for calls with a different identifier, which can be used to make the outcome of some events unaffected by others.
From what I understand, as well, giving your random function calls an identifier ensures that the game doesn't desync in multiplayer.
User avatar
Enjay
 
 
Posts: 26874
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: Problem with A_SpawnItemEx and flags

Post by Enjay »

Ah! thank you for both answers. Now that I look at the code, it should have been obvious that the flags were in the wrong place. I have no idea how I ended up with code that simply missed out the zvel parameter. Like I said, I don't really know where it came from (I know that I certainly wouldn't have written code with a number like 0.015625 without either being told to, or copying it from somewhere), but you've certainly identified the problem.

I did look in the wiki for the random identifier thing, and ended up on the random page which doesn't cover this.

Once again, thank you.
Blue Shadow
Posts: 5039
Joined: Sun Nov 14, 2010 12:59 am

Re: Problem with A_SpawnItemEx and flags

Post by Blue Shadow »

You're welcome.
Enjay wrote: Mon Mar 17, 2025 11:43 am I did look in the wiki for the random identifier thing, and ended up on the random page which doesn't cover this.
That's the ACS version of random() which doesn't allow setting those.

Return to “Scripting”