Need help with Spawn() in ZScript

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
etbasch
Posts: 25
Joined: Wed Apr 10, 2019 5:42 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Ukraine

Need help with Spawn() in ZScript

Post by etbasch »

I'm trying to enhance Doom's light sources with extra flares on top of them, but without replacing the original actors. So I have this LENSA0.png sprite that I would like to place on top of each Column and TechLamp spawned in Doom's map.

Code: Select all

class LightFlare : Actor {
	Default {
		+FIXMAPTHINGPOS
		+LOOKALLAROUND
		+NOTAUTOAIMED
		+NOBLOCKMAP
		+MOVEWITHSECTOR
		+NOGRAVITY
		+DROPOFF
		+NOTELEPORT
		+GHOST
		+THRUACTORS
		+BRIGHT
		+NOINTERACTION
		+NOCLIP
		+RELATIVETOFLOOR
		renderstyle "Add";
		}
	}

class ColumnFlare : LightFlare {
	Default {
		alpha 0.75;
		scale 0.33;
		}

	States {
		Spawn:
			TNT1 A 0 NoDelay A_CheckSight(3);
			TNT1 A 0 A_SetScale(0.33-random(1,5)*0.01);
			TNT1 A 0 A_Warp(AAPTR_MASTER,0,0,40,0,WARPF_NOCHECKPOSITION);
			LENS A 2 bright;
			loop;
		}
	}

class TechLampFlare : LightFlare {
	Default {
		alpha 0.75;
		scale 0.42;
		}

	States {
		Spawn:
			TNT1 A 0 NoDelay A_CheckSight(3);
			TNT1 A 0 A_SetScale(0.42-random(1,5)*0.01);
			TNT1 A 0 A_Warp(AAPTR_MASTER,0,0,70,0,WARPF_NOCHECKPOSITION);
			LENS A 2 bright;
			loop;
		}
	}

class LightEventHandler : EventHandler {
    override void WorldThingSpawned(WorldEvent e) {
		let a = e.Thing;
		if (a is "Column") {
			Spawn("ColumnFlare", pos.x, pos.y, pos.z + 40);
			}
		if (a is "TechLamp") {
			Spawn("TechLampFlare", pos.x, pos.y, pos.z + 67);
			}
		}
	}
For some reason, it does not work. The compiler says that Spawn() is an unknown function. But that function does exist, right? How do i fix the error?
Attachments
LENSA0.png
LENSA0.png (20.73 KiB) Viewed 916 times
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Need help with Spawn() in ZScript

Post by Player701 »

Spawn is a static method of Actor, but EventHandler is not a subclass of Actor. Therefore, you have to prefix the method name with the class name to call it, like this: Actor.Spawn(...)
User avatar
etbasch
Posts: 25
Joined: Wed Apr 10, 2019 5:42 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Ukraine

Re: Need help with Spawn() in ZScript

Post by etbasch »

Player701 wrote:Spawn is a static method of Actor, but EventHandler is not a subclass of Actor. Therefore, you have to prefix the method name with the class name to call it, like this: Actor.Spawn(...)
Now it says that Spawn() has too many arguments specified, although according this article it should have at least 4 parameters in it:
https://zdoom.org/wiki/Spawn
It looks like the Spawn method returns an int value and is used as a number in the examples, but even when I rewrite the code as

Code: Select all

int b = Spawn("ColumnFlare", pos.x, pos.y, pos.z + 40);
it still doesn't recognize the spawn function.
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Need help with Spawn() in ZScript

Post by Player701 »

The wiki article you linked to describes an ACS function named Spawn. It is not related to the Actor::Spawn method. Here is the signature of the latter:

Code: Select all

native static Actor Spawn(class<Actor> type, vector3 pos = (0,0,0), int replace = NO_REPLACE);
You should rewrite your code as:

Code: Select all

Actor.Spawn('ColumnFlare', (pos.x, pos.y, pos.z + 40));
User avatar
etbasch
Posts: 25
Joined: Wed Apr 10, 2019 5:42 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Ukraine

Re: Need help with Spawn() in ZScript

Post by etbasch »

Player701 wrote:

Code: Select all

Actor.Spawn('ColumnFlare', (pos.x, pos.y, pos.z + 40));
Thank you. It worked.
Post Reply

Return to “Scripting”