ZScript - Accept strings for switch blocks

Remember, just because you request it, that doesn't mean you'll get it.

Moderator: GZDoom Developers

User avatar
kevansevans
Spotlight Team
Posts: 409
Joined: Tue Oct 05, 2010 12:04 am
Graphics Processor: nVidia with Vulkan support

ZScript - Accept strings for switch blocks

Post by kevansevans »

As the title says, allow switch blocks to accept strings.

Code: Select all


switch (_string)
{
   case "cat" :
      //Do cat thing
      break;
   case "dog" :
      //do dog thing
      break;
}

User avatar
Zhs2
Posts: 1248
Joined: Fri Nov 07, 2008 3:29 pm
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Location: Maryland, USA, but probably also in someone's mod somewhere

Re: ZScript - Accept strings for switch blocks

Post by Zhs2 »

It's not what you're requesting but it might help you to know that (G)ZDoom's internal Name type (e.g. damage types) can be used as switch case labels, as they represent integers internally. Some fiddling to convert a String into a Name might do what you are looking for.

Return to “Feature Suggestions [GZDoom]”