Hi, having trouble with checking DisplayName in custom fucntion

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
TooCoolToo
Posts: 1
Joined: Tue Jul 29, 2025 9:16 am
Graphics Processor: nVidia (Modern GZDoom)

Hi, having trouble with checking DisplayName in custom fucntion

Post by TooCoolToo »

I made a custom class called "Badass". This function is supposed to check if the DoomPlayer is called "BadAss" or just "Marine". However, for some reason, it doesn't work. I've tried PlayerPawn and Actor, but DisplayName doesn't work?

GScript error, "C:/Users/Owner/Downloads/Doomed/:zscript" line 186:
GUnknown identifier 'DisplayName'

Execution could not continue.
1 errors while parsing scripts
Here is my code:


Code: Select all

class MyPlayer : DoomPlayer{	
Default
	{	Health 125 ;
		Player.MaxHealth 125 ; 
		Player.DisplayName "The Badass" ;
		Player.StartItem "Chainsaw";
		Player.StartItem "Fist";
		Player.StartItem "Pistol";
		Player.StartItem "Clip", 25;
		Player.StartItem "Vilestaff" ;
		Player.StartItem "DoomOrb", 10;
	}
	
	int GetActorName(DoomPlayer dplay) 
	{    
  // If the 'who' pointer is null, returns -1 and stops execution:
  if (dplay.DisplayName == "Marine")
  {
    return -1;
  }
  // Otherwise returns the health value of pointer 'who':
  return dplay.health;

    }   	





}
Bledan
Posts: 2
Joined: Fri May 02, 2025 2:46 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support

Re: Hi, having trouble with checking DisplayName in custom fucntion

Post by Bledan »

If I’m not mistaken, DisplayName isn’t an Actor’s variable but a property, which is a sort of alias used to assign default values on spawning (correct me if my explanation has some errors) and is tied to an actual variable but it’s NOT the variable itself and thus cannot be read by a function. Now I don’t know the corresponding variable, maybe someone else does?
User avatar
Nash
 
 
Posts: 17498
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: Hi, having trouble with checking DisplayName in custom fucntion

Post by Nash »

Code: Select all

if (dplay.GetPrintableDisplayName(dplay.GetClass()) ~== "Marine")
{
// etc

- You can't read DisplayName directly. You'll have to use the designated getter function GetPrintableDisplayName, which takes in an Actor Class argument, hence dplay.GetClass()
- ~== is a case-insensitive strings comparison. Documented on this page: https://zdoom.org/wiki/ZScript_data_types#Strings
Post Reply

Return to “Scripting”