Programmatically Spawning Moving Things

Moderator: GZDoom Developers

User avatar
SPZ1
Posts: 205
Joined: Wed Aug 02, 2017 3:01 pm
Location: Illinois

Programmatically Spawning Moving Things

Post by SPZ1 »

I just found out that this code to move some things does not work:

Code: Select all

script 10 (void){
	Thing_SpawnFacing(9, 230, TRUE, 50);
	Thing_SpawnFacing(10, 231, TRUE, 51);
	Thing_SpawnFacing(11, 232, TRUE, 52);
	Thing_SpawnFacing(12, 233, TRUE, 53);
	Thing_SpawnFacing(13, 234, TRUE, 54);
	Thing_SpawnFacing(14, 235, TRUE, 55);
	Thing_SpawnFacing(15, 236, TRUE, 56);
	Thing_SpawnFacing(16, 237, TRUE, 57);

	Thing_SpawnNoFog(17, 9074, 0, 58);
	SetThingSpecial(58, 0, 1, 0, 3, 50);
	Thing_SpawnNoFog(18, 9074, 0, 59);
	SetThingSpecial(59, 0, 2, 0, 3, 51);
	Thing_SpawnNoFog(19, 9074, 0, 60);
	SetThingSpecial(60, 0, 3, 0, 3, 52);
	Thing_SpawnNoFog(20, 9074, 0, 61);
	SetThingSpecial(61, 0, 4, 0, 3, 53);
	Thing_SpawnNoFog(21, 9074, 0, 62);
	SetThingSpecial(62, 0, 5, 0, 3, 54);
	Thing_SpawnNoFog(22, 9074, 0, 63);
	SetThingSpecial(63, 0, 6, 0, 3, 55);
	Thing_SpawnNoFog(23, 9074, 0, 64);
	SetThingSpecial(64, 0, 7, 0, 3, 56);
	Thing_SpawnNoFog(24, 9074, 0, 65);
	SetThingSpecial(65, 0, 8, 0, 3, 57);

	Thing_Activate(58);
	Thing_Activate(59);
	Thing_Activate(60);
	Thing_Activate(61);
	Thing_Activate(62);
	Thing_Activate(63);
	Thing_Activate(64);
	Thing_Activate(65);
}
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 47976
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Programmatically Spawning Moving Things

Post by Graf Zahl »

In what way does thus not work? What are you trying to do here?
User avatar
SPZ1
Posts: 205
Joined: Wed Aug 02, 2017 3:01 pm
Location: Illinois

Re: Programmatically Spawning Moving Things

Post by SPZ1 »

I'm trying to code a shooting gallery where the targets move around in a circle. I made this .WAD quickly to demonstrate. Just use "Puke 10" in the console.
You do not have the required permissions to view the files attached to this post.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 47976
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Programmatically Spawning Moving Things

Post by Graf Zahl »

Let me get this straight: You are trying to spawn some ActorMovers by calling Thing_SpawnNoFog with an EDITOR NUMBER as second parameter?
Well, that cannot work - you need to pass a spawn ID.
User avatar
SPZ1
Posts: 205
Joined: Wed Aug 02, 2017 3:01 pm
Location: Illinois

Re: Programmatically Spawning Moving Things

Post by SPZ1 »

Sorry about that...
:bang: :bang: :bang:
User avatar
Enjay
 
 
Posts: 26403
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: Programmatically Spawning Moving Things

Post by Enjay »

Graf is, of course, correct. However, for your case, might you be able to use one of the spawn functions ( [wiki]Spawn[/wiki], [wiki]SpawnSpot[/wiki], [wiki]SpawnSpotFacing[/wiki], [wiki]SpawnForced[/wiki], [wiki]SpawnSpotForced[/wiki], [wiki]SpawnSpotFacingForced[/wiki] or maybe even [wiki]SpawnProjectile[/wiki] )?

It's likely that one of them will suit your needs and they don't even need a spawn id (which I'm not even sure that ActorMover class had by default). You simply pass the class name as a string to the spawn function.
User avatar
SPZ1
Posts: 205
Joined: Wed Aug 02, 2017 3:01 pm
Location: Illinois

Re: Programmatically Spawning Moving Things

Post by SPZ1 »

I got the code to work but I noticed something strange. If I "puke 10" this code without the Delay(1); then I have to "puke 10" twice instead of once and I don't know why.

Code: Select all

script 10 (void){
	Thing_SpawnFacing(9, 230, TRUE, 50);
	Thing_SpawnFacing(10, 231, TRUE, 51);
	Thing_SpawnFacing(11, 232, TRUE, 52);
	Thing_SpawnFacing(12, 233, TRUE, 53);
	Thing_SpawnFacing(13, 234, TRUE, 54);
	Thing_SpawnFacing(14, 235, TRUE, 55);
	Thing_SpawnFacing(15, 236, TRUE, 56);
	Thing_SpawnFacing(16, 237, TRUE, 57);

	//Delay(1);

	Thing_SpawnNoFog(17, 238, 0, 58);
	SetThingSpecial(58, 0, 1, 0, 3, 50);
	Thing_SpawnNoFog(18, 238, 0, 59);
	SetThingSpecial(59, 0, 2, 0, 3, 51);
	Thing_SpawnNoFog(19, 238, 0, 60);
	SetThingSpecial(60, 0, 3, 0, 3, 52);
	Thing_SpawnNoFog(20, 238, 0, 61);
	SetThingSpecial(61, 0, 4, 0, 3, 53);
	Thing_SpawnNoFog(21, 238, 0, 62);
	SetThingSpecial(62, 0, 5, 0, 3, 54);
	Thing_SpawnNoFog(22, 238, 0, 63);
	SetThingSpecial(63, 0, 6, 0, 3, 55);
	Thing_SpawnNoFog(23, 238, 0, 64);
	SetThingSpecial(64, 0, 7, 0, 3, 56);
	Thing_SpawnNoFog(24, 238, 0, 65);
	SetThingSpecial(65, 0, 8, 0, 3, 57);

	//Delay(1);

	Thing_Activate(58);
	Thing_Activate(59);
	Thing_Activate(60);
	Thing_Activate(61);
	Thing_Activate(62);
	Thing_Activate(63);
	Thing_Activate(64);
	Thing_Activate(65);
}
Also:

Code: Select all

ACTOR NewActorMover : ActorMover { SpawnID 238 }
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 47976
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Programmatically Spawning Moving Things

Post by Graf Zahl »

You need the delay so that the ActorMover setup is only done when the stuff you spawned first with Thing_SpawnFacing has been fully initialized.

Return to “Closed Feature Suggestions”