ZScript - Accept strings for switch blocks

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

Moderator: GZDoom Developers

ZScript - Accept strings for switch blocks

Postby kevansevans » Fri Dec 03, 2021 3:00 pm

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

Code: Select allExpand view

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

User avatar
kevansevans
Disciple of The Great God Imp
Spotlight Team
 
Joined: 05 Oct 2010
Github ID: kevansevans
Operating System: Windows 10/8.1/8/201x 64-bit
Graphics Processor: nVidia with Vulkan support

Re: ZScript - Accept strings for switch blocks

Postby Zhs2 » Fri Dec 03, 2021 5:45 pm

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.
User avatar
Zhs2
Power of meh.
 
Joined: 07 Nov 2008
Location: Maryland, USA, but probably also in someone's mod somewhere
Operating System: Windows 10/8.1/8/201x 64-bit
Graphics Processor: ATI/AMD with Vulkan Support


Return to Feature Suggestions

Who is online

Users browsing this forum: No registered users and 1 guest