Zscript base Class help

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
GiveOneMoreChance
Posts: 19
Joined: Thu Aug 10, 2017 8:09 pm

Zscript base Class help

Post by GiveOneMoreChance »

Hello! It's possible to with Zscript create base Class and change his parameters with custom functions?

example :

Code: Select all

Class Smoke : Actor
{
	double smokeScaling;
	double smokeFadeSpeed;
	
	property Scaling: smokeScaling;
	property FadeSpeed: smokeFadeSpeed;
	
	Default
	{
	Radius 8;
	Height 8;
	Projectile;
	Speed 16;
 	+RANDOMIZE;
	+NOCLIP;
	+CLIENTSIDEONLY;
	+FORCEXYBILLBOARD;
	+ROLLSPRITE;
	+ROLLCENTER;
	RenderStyle "Translucent";
	Scale 0.2;
	Alpha 0.5;
	Smoke.Scaling 0.005;
	Smoke.FadeSpeed 0.01;
	}
    States
    {
    Spawn:
		TNT1 A 1
		{
			if(random(0,101) > 50)
			{
				A_ChangeFlag("SPRITEFLIP",TRUE);
			}
		}
	Death:
		SMOK A 1
		{
			A_FadeOut(FadeSpeed);
			A_SetScale((scale.x + Scaling));
			ThrustThingZ (0, 1, 0, 0);			
		}
		Loop;
    }
}

Action void A_FireProjectileSmoke(class<Actor> missiletype, double FadeSpeed = 0.005, double smokeScaling = 0.01, double angle = 0, bool useammo = true, double spawnofs_xy = 0, double spawnheight = 0, int flags = 0, double pitch = 0)
{
//pseudo code
Smoke.Scaling = smokeScaling;
Smoke.FadeSpeed = FadeSpeed;
//other code for spawn smoke with parameters 
}
User avatar
AFADoomer
Posts: 1324
Joined: Tue Jul 15, 2003 4:18 pm
Contact:

Re: Zscript base Class help

Post by AFADoomer »

I'm not 100% sure what you're trying to do here...

You have to spawn the actor to be able to modify its variables:

Code: Select all

action void A_Whatever(...)
{
    Smoke mo = Spawn("Smoke", pos);

    if (mo)
    {
        mo.smokeScaling  = 1.5;
        mo.smokeFadeSpeed = 10.0;
    }
}
Properties are used if you have a new class that inherits from Smoke:

Code: Select all

Class NewSmoke : Smoke
{
    Default
    {
        Smoke.Scaling = 1.5; // maps to the smokeScaling variable
        Smoke.FadeSpeed = 10.0; // maps the the smokeFadeSpeed variable
    }
} 
You have to use the variable names internally in any code - so your Death state is using invalid variables ('FadeSpeed' and 'Scaling')... I'd be surprised if this code even runs without errors.
GiveOneMoreChance
Posts: 19
Joined: Thu Aug 10, 2017 8:09 pm

Re: Zscript base Class help

Post by GiveOneMoreChance »

1 solution it's what it's need, but
it give Cannot convert Pointer<Class<Actor>> to Pointer<Class<Smoke>> and Unknown identifier 'mo'. Thanks AFADoomer.
Working code:

Code: Select all

	Action void A_SpawnSmoke(class<Actor> missiletype, double FadeSpeed = 0.1, double smokeScaling = 0.005)
	{
		actor test = Spawn("BaseSmoke", pos);
		let smoke = BaseSmoke(test);
	
		if (smoke)
		{
			smoke.smokeScaling = smokeScaling;
			smoke.smokeFadeSpeed = FadeSpeed;
		}
	}
Can i simplify the working code?
User avatar
AFADoomer
Posts: 1324
Joined: Tue Jul 15, 2003 4:18 pm
Contact:

Re: Zscript base Class help

Post by AFADoomer »

Yep, you're right - I didn't actually test what I posted. Spawn returns an Actor, so Smoke there won't work.

Just doing this should work, too. No need to use 'let' separately.

Code: Select all

   Action void A_SpawnSmoke(class<Actor> missiletype, double FadeSpeed = 0.1, double smokeScaling = 0.005)
   {
      let smoke = Spawn("BaseSmoke", pos);
   
      if (smoke)
      {
         smoke.smokeScaling = smokeScaling;
         smoke.smokeFadeSpeed = FadeSpeed;
      }
   } 
Alternatively you could do:

Code: Select all

   Action void A_SpawnSmoke(class<Actor> missiletype, double FadeSpeed = 0.1, double smokeScaling = 0.005)
   {
      Actor test = Spawn("BaseSmoke", pos);
  
      if (test)
      {
         BaseSmoke(test).smokeScaling = smokeScaling;
         BaseSmoke(test).smokeFadeSpeed = FadeSpeed;
      }
   } 
Which isn't cleaner or shorter, but good for understanding how the code can work.
Locked

Return to “Editing (Archive)”