A_RepeatVar/Array

Moderator: GZDoom Developers

Post Reply
User avatar
Major Cooke
Posts: 8215
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

A_RepeatVar/Array

Post by Major Cooke »

A_RepeatVar/Array

These functions are something I created to help ease the pain of maintaining loops, and loops inside of loops because whenever something goes wrong (and it ALWAYS has that possibility), debugging complex loops can be a total bitch when there's multiple A_SetUserVar/Arrays involved. This takes care of automatic jumping back to specified states while the actor still needs to loop, and jumping into the appropriate state or not jumping at all when it reaches the quota.

In short, one could think of this as a for loop (or make it into a while loop if you want! Just set the increment to 0.)

This could also be thought of as an if/else statement when used properly, just no "else ifs" and it only works with user vars/arrays.

This function is capable of incrementing and decrementing.

Parameters:
  • State Progress - If the repeating is still "in progress", this is where the function will jump to.
  • user(var/array) - The name of the user variable/array goes here. For an array, it works just like how A_SetUserArray is worked, i.e. A_SetUserArray(user_t,0,1).
    • Position (Array Only) - The position of the array to modify its contents.
  • Increment - How much to increment (or decrement if going down) whenever pushing the "varray" closer to the limit.
  • Limit - The goal for the function to reach, in terms of incrementing a user var.
  • Flags - See below. Optional.
  • Final Value - If the limit is reached, the function will set the user var to this value once completed. Optional.
  • State Finished - This is the state the function will jump to instead of the progress state if the function completes setting the increment to the limit. Optional
Flags:
  • RPF_OVERCOUNT - If the function exceeds above/below the limit based upon which direction it's going, it would set it directly to the limit/final var and discard anything else. This flag makes it keep the leftovers and apply them to whatever the variable is set to, after it's set.
  • RPF_KEEPVAR - If final var is 0, instead of setting the var to 0 as well, keep it at the limit (and overcount if specified).
Example usage...

This cybie will only fire one rocket when he attacks for the very first time, and only the first time. Every other time, he will fire 3 rockets as usual, featuring the (in/de)crement abilities, unless he is interrupted by pain. In which case, he must finish his volley before being able to fire another full 3 rounds at his foe.

Code: Select all

Actor MCD : CyberDemon
{
	var int user_t[1];
	+BUDDHA
	+DONTRIP
	+REFLECTIVE
	States
	{
	See:
		CYBR A 3 A_Hoof
		CYBR A 0 A_SpawnItemEx("MCDShadow",0,0,0,0,0,0,0,32|SXF_TRANSFERSPRITEFRAME)
		CYBR A 3 A_Chase
		CYBR A 0 A_SpawnItemEx("MCDShadow",0,0,0,0,0,0,0,32|SXF_TRANSFERSPRITEFRAME)
		CYBR B 3 A_Chase
		CYBR B 0 A_SpawnItemEx("MCDShadow",0,0,0,0,0,0,0,32|SXF_TRANSFERSPRITEFRAME)
		CYBR B 3 A_Chase
		CYBR B 0 A_SpawnItemEx("MCDShadow",0,0,0,0,0,0,0,32|SXF_TRANSFERSPRITEFRAME)
		CYBR C 3 A_Chase
		CYBR C 0 A_SpawnItemEx("MCDShadow",0,0,0,0,0,0,0,32|SXF_TRANSFERSPRITEFRAME)
		CYBR C 3 A_Chase
		CYBR C 0 A_SpawnItemEx("MCDShadow",0,0,0,0,0,0,0,32|SXF_TRANSFERSPRITEFRAME)
		CYBR D 3 A_Metal
		CYBR D 0 A_SpawnItemEx("MCDShadow",0,0,0,0,0,0,0,32|SXF_TRANSFERSPRITEFRAME)
		CYBR D 3 A_Chase
		CYBR D 0 A_SpawnItemEx("MCDShadow",0,0,0,0,0,0,0,32|SXF_TRANSFERSPRITEFRAME)
		Loop
	Missile:
	Missile2: //Fires only ONE rocket, on its VERY FIRST EVER attack. After that, fires 3 like normal.
		CYBR E 12 A_FaceTarget
		CYBR E 0 A_LogInt(user_t[0])
		CYBR F 12 A_CyberAttack
		"####" "#" 0 A_RepeatArray("Missile2",user_t,0,1,0,0,3,"See")
		"####" "#" 0 A_LogInt(user_t[0]) //This frame will never be reached.
		Goto See
	}
}

Actor MCDShadow
{
	+NOINTERACTION
	Alpha 0.75
	States
	{
	Spawn:
		"####" "#" 1 A_FadeOut(0.05)
		Wait
	}
}
User avatar
randi
Site Admin
Posts: 7749
Joined: Wed Jul 09, 2003 10:30 pm
Contact:

Re: A_RepeatVar/Array

Post by randi »

Uh... No. This looks like it is totally and completely WFDS territory here. I'm still trying to figure out what exactly this does. This looks very dirty.
User avatar
Major Cooke
Posts: 8215
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: A_RepeatVar/Array

Post by Major Cooke »

I figured it might have been WFDS, but truthfully, I didn't know when we would see the ability to use {}, if and else statements officially in the repository -- something I'm still extremely stoked upon.

It's also not as dirty as it seems... at least it doesn't do anything other than fetch and set user vars/arrays of the calling actor only.
User avatar
Enjay
 
 
Posts: 27275
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: A_RepeatVar/Array

Post by Enjay »

randi wrote:WFDS
Wait for script?

But... But... We've all been waiting for Doomscript. It's like 64.cab all over again. :lol:
User avatar
Major Cooke
Posts: 8215
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: A_RepeatVar/Array

Post by Major Cooke »

Enjay wrote:
randi wrote:WFDS
Wait for script?

But... But... We've all been waiting for Doomscript. It's like 64.cab all over again. :lol:
Precisely why I made this, to tie us over in the mean time. I'm dying for the ability to use brackets and if/else statements!

EDIT: Oh, wait, I see what you did there. XD

Yeah, makes sense considering ZDoom covers more than just the DooM games.
User avatar
NeuralStunner
 
 
Posts: 12328
Joined: Tue Jul 21, 2009 12:04 pm
Preferred Pronouns: No Preference
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support
Location: capital N, capital S, no space
Contact:

Re: A_RepeatVar/Array

Post by NeuralStunner »

I think I'd rather see Randy (and Graf if he's interested) make these sorts of complex grammar extensions.
User avatar
Major Cooke
Posts: 8215
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: A_RepeatVar/Array

Post by Major Cooke »

And I'd rather try and fail than not try at all. Good learning cycle for finding out what I can and cannot do. What's the use of me sitting on my ass and doing nothing while brimming with ideas that others just might happen to benefit from?

I knew it probably wouldnt have sat well with Randi and/or Graf...

inb4 "Then why did you do it?"

'Cause I thought it would be extremely useful should it be accepted. I had a whole load of plans. Just because it backfired doesn't mean I've lost everything. No, it was merely a setback, nothing more. Just means, like the tag says, I have to wait.
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”