A_SetDuration Code Pointer
Moderator: GZDoom Developers
- The Slimeinator
- Posts: 44
- Joined: Fri Jun 26, 2009 1:23 pm
A_SetDuration Code Pointer
I saw this in an old Feature Suggestion topic.
How about a code pointer that sets the duration of the calling frame? This could be useful for objects and monsters that need chaotic and unpredictable behavior.
How about a code pointer that sets the duration of the calling frame? This could be useful for objects and monsters that need chaotic and unpredictable behavior.
- XutaWoo
- Posts: 4005
- Joined: Sat Dec 30, 2006 4:25 pm
- Location: beautiful hills of those who are friends
- Contact:
Re: A_SetDuration Code Pointer
Code: Select all
BAL1 A 2
^
There you go- InsanityBringer
- Posts: 3392
- Joined: Thu Jul 05, 2007 4:53 pm
- Location: opening the forbidden box
Re: A_SetDuration Code Pointer
Allowing random at the usual duration spot (if it isn't already) would be better than this. If this goes in as said here to do random states it would require this:
For something complex it would be even worse. If it was put into the usual duration spot, it would be this
I'm not sure if this will be implemented though. It deplends on how the state system works, which currently, if I am right, creates a fixed table of all the states needed at run-time. I could be horribly wrong though.
Code: Select all
POSS A 0 A_PosAttack
POSS A 0 A_SetDuration(random(1,10)Code: Select all
POSS A random(1,10) A_PosAttack- The Slimeinator
- Posts: 44
- Joined: Fri Jun 26, 2009 1:23 pm
Re: A_SetDuration Code Pointer
The second version you posted was what the original feature suggestion was about and the reason it got no'd. Graf suggested suggesting a code pointer to change state duration instead.InsanityBringer wrote:Allowing random at the usual duration spot (if it isn't already) would be better than this. If this goes in as said here to do random states it would require this:
For something complex it would be even worse. If it was put into the usual duration spot, it would be thisCode: Select all
POSS A 0 A_PosAttack POSS A 0 A_SetDuration(random(1,10)
I'm not sure if this will be implemented though. It deplends on how the state system works, which currently, if I am right, creates a fixed table of all the states needed at run-time. I could be horribly wrong though.Code: Select all
POSS A random(1,10) A_PosAttack
- Ryan Cordell
- Posts: 4349
- Joined: Sun Feb 06, 2005 6:39 am
- Preferred Pronouns: No Preference
- Operating System Version (Optional): Windows 10
- Graphics Processor: nVidia (Modern GZDoom)
- Location: Capital of Explodistan
Re: A_SetDuration Code Pointer
Trouble is, how would A_SetDuration know which frame to modify? If it's in a zero duration frame, does it modify the "previous" frame (the one above with any duration)? Does it modify itself? What about the frame which has a duration and calls the function?
I dunno, this just isn't clicking with me.
I dunno, this just isn't clicking with me.
Re: A_SetDuration Code Pointer
SetDuration might be a bad name for it. I would do something like A_Delay, or maybe A_FrameDelay. What it would do is freeze the monster at the current frame (as if the duration had been set there) and not allow it to proceed until the delay is up. I would treat the specified frame duration as being in addition to anything passed in from the code pointer.
For example, take this code snippet:
Here's how I would envision this would work:
1) Frame A is reached, no code pointer, so the actor is just set to the A frame for 4 tics.
2) Frame B is reached, at which point A_Delay is run and the monster is set at frame B for 5 - 10 tics depending on the result.
3) Since there's no duration on frame B, frame C is reached next and A_Delay is run again, holding the actor at frame C for 0 - 2 tics.
4) Frame C's normal 5-frame delay would then be waited out, so the end result is the actor is held at C for 5 - 7 tics.
5) Frame D is reached, no code pointer to run and no delay, so the monster immediately gets set to frame E as normal.
The way Decorate is currently set up, the delay would more accurately hold the actor at the previous frame, but that might be more confusing to authors.
For example, take this code snippet:
Code: Select all
MONS A 4
MONS B 0 A_Delay (random (5, 10))
MONS C 5 A_Delay (random (0, 2))
MONS D 0
MONS E 71) Frame A is reached, no code pointer, so the actor is just set to the A frame for 4 tics.
2) Frame B is reached, at which point A_Delay is run and the monster is set at frame B for 5 - 10 tics depending on the result.
3) Since there's no duration on frame B, frame C is reached next and A_Delay is run again, holding the actor at frame C for 0 - 2 tics.
4) Frame C's normal 5-frame delay would then be waited out, so the end result is the actor is held at C for 5 - 7 tics.
5) Frame D is reached, no code pointer to run and no delay, so the monster immediately gets set to frame E as normal.
The way Decorate is currently set up, the delay would more accurately hold the actor at the previous frame, but that might be more confusing to authors.
- The Slimeinator
- Posts: 44
- Joined: Fri Jun 26, 2009 1:23 pm
Re: A_SetDuration Code Pointer
With A_Delay, there could be a problem with calling another function at the same time with a zero duration frame prior to the A_Delay frame.
Re: A_SetDuration Code Pointer
Not really. Wouldn't it already execute that function, and move on? Granted, it would probably use the sprite as the previous frame, but it would have already activated the previous frame's function?The Slimeinator wrote:With A_Delay, there could be a problem with calling another function at the same time with a zero duration frame prior to the A_Delay frame.
- The Slimeinator
- Posts: 44
- Joined: Fri Jun 26, 2009 1:23 pm
Re: A_SetDuration Code Pointer
Perhaps you're right.
Re: A_SetDuration Code Pointer
In looking at the way ZDoom does things, I think the easiest solution would be to make A_Delay do what it says on the tin -- Simply wait X tics before continuing on to its own frame. A special before it on a 0-duration frame will be executed, followed immediately by the A_Delay, which will then create a delay at the previous frame (that does mean TNT1 A 0 A_SomeFunc -> MONS E 0 A_Delay (5) would cause the enemy to render invisible for 5 tics). This is in line with how ZDoom processes specials attached to frames, but I can almost guarantee it will cause some author confusion at some point.
Re: A_SetDuration Code Pointer
All the more reason for a note in the wiki about it.HotWax wrote:I can almost guarantee it will cause some author confusion at some point.
Re: A_SetDuration Code Pointer
Can't you do a loop that can be randomly exited?
Re: A_SetDuration Code Pointer
[wiki]A_Jump[/wiki]printz wrote:Can't you do a loop that can be randomly exited?
Re: A_SetDuration Code Pointer
You could, yes. But you can do more with A_Delay than simply have random delays...printz wrote:Can't you do a loop that can be randomly exited?
Also, this is now a code submission: http://forum.zdoom.org/viewtopic.php?f=34&t=22639
Re: A_SetDuration Code Pointer
Yes. I knew and I said that as a solution to have random duration events.SoulPriestess wrote:[wiki]A_Jump[/wiki]printz wrote:Can't you do a loop that can be randomly exited?