Page 1 of 1

Repeating (almost) the same decorate code

Posted: Sat Nov 17, 2012 6:11 am
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.

Re: Repeating (almost) the same decorate code

Posted: Sat Nov 17, 2012 6:25 am
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.

Re: Repeating (almost) the same decorate code

Posted: Sat Nov 17, 2012 6:59 am
by cocka
Thank you. I'll give it a try.

Re: Repeating (almost) the same decorate code

Posted: Sat Nov 17, 2012 7:26 am
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.

Re: Repeating (almost) the same decorate code

Posted: Sat Nov 17, 2012 7:31 am
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.

Re: Repeating (almost) the same decorate code

Posted: Sat Nov 17, 2012 8:11 am
by cocka
Is the rhythm of the shards spawning correct, at least?
Yes it is. Thanks.

Re: Repeating (almost) the same decorate code

Posted: Sat Nov 17, 2012 8:22 am
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.)

Re: Repeating (almost) the same decorate code

Posted: Sun Nov 18, 2012 5:11 am
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.

Re: Repeating (almost) the same decorate code

Posted: Sun Nov 18, 2012 5:22 am
by Gez
There are five args, at positions 0, 1, 2, 3, and 4.

Re: Repeating (almost) the same decorate code

Posted: Sun Nov 18, 2012 5:51 am
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