Type casting null

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!)
User avatar
Xtyfe
Posts: 1484
Joined: Fri Dec 14, 2007 6:29 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support

Type casting null

Post by Xtyfe »

The following code in the See state does not work. I understand that I can't use statelabels in ternary expressions and that I must cast it. I'm only vaguely familiar with casting, but I'm not sure how to cast "null" in this situation. Is there a better way than what I'm doing?

Code: Select all

class Archvile : Actor
{
	state nullstate;
	
	Default
	{
		Health 700;
		Radius 20;
		Height 56;
		Mass 500;
		Speed 15;
		PainChance 10;
		Monster;
		MaxTargetRange 896;
		+QUICKTORETALIATE 
		+FLOORCLIP 
		+NOTARGET
		SeeSound "vile/sight";
		PainSound "vile/pain";
		DeathSound "vile/death";
		ActiveSound "vile/active";
		MeleeSound "vile/stop";
		Obituary "$OB_VILE";
		Tag "$FN_ARCH";
	}

	override void PostBeginPlay()
	{
		let nullstate = SetState(null);
	}
	
	States
	{
	Spawn:
		VILE AB 10 A_Look;
		Loop;
	See:
		VILE AABBCCDDEEFF 2 A_Chase ((CheckLOF (CLOFF_MUSTBESOLID)) ? "nullstate" : "Melee", (CheckLOF (CLOFF_MUSTBESOLID)) ? "nullstate" : "Missile", CHF_RESURRECT);
		Loop;
	Missile:
		VILE G 0 BRIGHT A_VileStart;
		VILE G 10 BRIGHT A_FaceTarget;
		VILE H 8 BRIGHT A_VileTarget;
		VILE IJKLMN 8 BRIGHT A_FaceTarget;
		VILE O 8 BRIGHT A_VileAttack;
		VILE P 20 BRIGHT;
		Goto See;
	Heal:
		VILE [\] 10 BRIGHT;
		Goto See;
	Pain:
		VILE Q 5;
		VILE Q 5 A_Pain;
		Goto See;
	Death:
		VILE Q 7;
		VILE R 7 A_Scream;
		VILE S 7 A_NoBlocking;
		VILE TUVWXY 7;
		VILE Z -1;
		Stop;
	}
}
Blue Shadow
Posts: 5019
Joined: Sun Nov 14, 2010 12:59 am

Re: Type casting null

Post by Blue Shadow »

From my experience type-casting StateLabels doesn't work (my guess it's not supported), so it's better to rewrite that code, to something like this:

Code: Select all

See:
	VILE AABBCCDDEEFF 2
	{
		StateLabel meleelabel = 'Melee', missilelabel = 'Missile';

		if (CheckLOF(CLOFF_MUSTBESOLID))
		{
			meleelabel = missilelabel = null;
		}

		A_Chase(meleelabel, missilelabel, CHF_RESURRECT);
	}
	Loop;
User avatar
Xtyfe
Posts: 1484
Joined: Fri Dec 14, 2007 6:29 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support

Re: Type casting null

Post by Xtyfe »

That works perfectly. Thank you for the help.

Return to “Scripting”