Repeating (almost) the same decorate code

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
User avatar
cocka
Posts: 1520
Joined: Sat Jul 02, 2011 7:21 am
Location: Hungary

Repeating (almost) the same decorate code

Post by cocka »

Is there a way to cut down this decorate code? I mean, I would like something like for loop in acs. Is there an option for it in decorate, so that you don't have to write lots of lines with the same (or almost the same) code.

Code: Select all

actor cloudpot : Pottery1 11003
{
States
  {
  Spawn:
    POT1 A -1
    Loop
  Death:
    POT1 A 0 A_PotteryExplode
	POT1 A 0 A_SpawnItemEx("PoisonCloud", frandom(-30.0, 30.0), frandom(-30.0, 30.0), 40.0, frandom(0.0,10.0), frandom(0.0,10.0), 0.0, 0.0, SXF_NOCHECKPOSITION, 0)
	NULL A 35 
	POT1 A 0 A_SpawnItemEx("PoisonCloud", frandom(-30.0, 30.0), frandom(-30.0, 30.0), 40.0, frandom(0.0,10.0), frandom(0.0,10.0), 0.0, 0.0, SXF_NOCHECKPOSITION, 0)
	NULL A 35
	POT1 A 0 A_SpawnItemEx("PoisonCloud", frandom(-30.0, 30.0), frandom(-30.0, 30.0), 40.0, frandom(0.0,10.0), frandom(0.0,10.0), 0.0, 0.0, SXF_NOCHECKPOSITION, 0)
	NULL A 35
	POT1 A 0 A_SpawnItemEx("PoisonCloud", frandom(-30.0, 30.0), frandom(-30.0, 30.0), 40.0, frandom(0.0,10.0), frandom(0.0,10.0), 0.0, 0.0, SXF_NOCHECKPOSITION, 0)
	NULL A 35
	POT1 A 0 A_SpawnItemEx("PoisonCloud", frandom(-30.0, 30.0), frandom(-30.0, 30.0), 40.0, frandom(0.0,10.0), frandom(0.0,10.0), 0.0, 0.0, SXF_NOCHECKPOSITION, 0)
	NULL A 35
	POT1 A 0 A_SpawnItemEx("PoisonCloud", frandom(-30.0, 30.0), frandom(-30.0, 30.0), 40.0, frandom(0.0,10.0), frandom(0.0,10.0), 0.0, 0.0, SXF_NOCHECKPOSITION, 0)
	NULL A 35
	POT1 A 1 A_SpawnItemEx("PoisonCloud", frandom(-30.0, 30.0), frandom(-30.0, 30.0), 40.0, frandom(0.0,10.0), frandom(0.0,10.0), 0.0, 0.0, SXF_NOCHECKPOSITION, 0)
	NULL A 35
	POT1 A 1 A_SpawnItemEx("PoisonCloud", frandom(-30.0, 30.0), frandom(-30.0, 30.0), 40.0, frandom(0.0,10.0), frandom(0.0,10.0), 0.0, 0.0, SXF_NOCHECKPOSITION, 0)
	NULL A 35
	POT1 A 1 A_SpawnItemEx("PoisonCloud", frandom(-30.0, 30.0), frandom(-30.0, 30.0), 40.0, frandom(0.0,10.0), frandom(0.0,10.0), 0.0, 0.0, SXF_NOCHECKPOSITION, 0)
	NULL A 35
	POT1 A 1 A_SpawnItemEx("PoisonCloud", frandom(-30.0, 30.0), frandom(-30.0, 30.0), 40.0, frandom(0.0,10.0), frandom(0.0,10.0), 0.0, 0.0, SXF_NOCHECKPOSITION, 0)
    Stop
  }
Substituting Loop for Stop is not a good idea, because I want A_PotteryExplode to be executed only once and I'd like to spawn clouds finite times not in a Loop. Otherwise how do you stop a Loop if you don't want to run it forever? In acs it would be much easier.
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Graphics Processor: nVidia with Vulkan support
Location: Maryland, US
Contact:

Re: Repeating (almost) the same decorate code

Post by Ed the Bat »

Code: Select all

actor cloudpot : Pottery1 11003
{
	States
	{
	Spawn:
		POT1 A -1
		Loop
	Death:
		POT1 A 0 A_PotteryExplode
		POT1 AAAAAA 35 A_SpawnItemEx("PoisonCloud", frandom(-30.0, 30.0), frandom(-30.0, 30.0), 40.0, frandom(0.0,10.0), frandom(0.0,10.0), 0.0, 0.0, SXF_NOCHECKPOSITION, 0)
		POT1 AAAA 36 A_SpawnItemEx("PoisonCloud", frandom(-30.0, 30.0), frandom(-30.0, 30.0), 40.0, frandom(0.0,10.0), frandom(0.0,10.0), 0.0, 0.0, SXF_NOCHECKPOSITION, 0)
		Stop
}
Try that.
User avatar
cocka
Posts: 1520
Joined: Sat Jul 02, 2011 7:21 am
Location: Hungary

Re: Repeating (almost) the same decorate code

Post by cocka »

Thank you. I'll give it a try.
User avatar
cocka
Posts: 1520
Joined: Sat Jul 02, 2011 7:21 am
Location: Hungary

Re: Repeating (almost) the same decorate code

Post by cocka »

The pot graphic always appears so it isn't the proper solution. After you smash the pot, pot graphic shouldn't be spawned any more.
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Graphics Processor: nVidia with Vulkan support
Location: Maryland, US
Contact:

Re: Repeating (almost) the same decorate code

Post by Ed the Bat »

My mistake. I'm running on very little sleep. Is the rhythm of the shards spawning correct, at least? Anyway, replace POT1 in the Death state with TNT1 and it'll be invisible.
User avatar
cocka
Posts: 1520
Joined: Sat Jul 02, 2011 7:21 am
Location: Hungary

Re: Repeating (almost) the same decorate code

Post by cocka »

Is the rhythm of the shards spawning correct, at least?
Yes it is. Thanks.
Gez
 
 
Posts: 17946
Joined: Fri Jul 06, 2007 3:22 pm

Re: Repeating (almost) the same decorate code

Post by Gez »

Your original code has the pot sprite blinking quickly towards the end (POT1 A 1 will make it appear for one tic). I don't know if it's intentional.

If so, you can still use Loop, but with these two things:

[wiki]A_SetArg[/wiki]
[wiki]A_CountdownArg[/wiki]

Use A_SetArg before the loop. Then insert a new state label and place A_CountdownArg within the loop.

(You can also use [wiki]DECORATE expressions[/wiki] to do the same thing.)
User avatar
cocka
Posts: 1520
Joined: Sat Jul 02, 2011 7:21 am
Location: Hungary

Re: Repeating (almost) the same decorate code

Post by cocka »

if it's intentional.
No, it was a mistake. :)

I wish I were familiar with this SetArg function, but I don't know how it works. What is this: args[position]. Where can you set it?

Though, I think I would rather use a script calling function in the code, because I don't know what this is all about, but I need a for loop to have a ring of clouds around the player.
Gez
 
 
Posts: 17946
Joined: Fri Jul 06, 2007 3:22 pm

Re: Repeating (almost) the same decorate code

Post by Gez »

There are five args, at positions 0, 1, 2, 3, and 4.
User avatar
cocka
Posts: 1520
Joined: Sat Jul 02, 2011 7:21 am
Location: Hungary

Re: Repeating (almost) the same decorate code

Post by cocka »

Ok, now let's see this example:

Code: Select all

ACTOR FloatBobHealthBonus HealthBonus
{
 States
 {
 Spawn:
   BON1 A 0 A_JumpIf(Args[0]<0, "FloatBobMovement")
   BON1 ABCDCB 6
   Loop
 FloatBobMovement:
   BON1 A 0 A_SetArg(0, 0)
   BON1 A 0 A_ChangeFlag("FLOATBOB", 1)
   Goto Spawn
 }
}
Now, in this case how do you know what value Args[0] has? There might be a mistake because the text says
if its first argument (Args[0]) is higher than 0
. :D
Locked

Return to “Editing (Archive)”