User error or bug?

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
Kizoky
Posts: 285
Joined: Mon Nov 14, 2011 9:59 am
Graphics Processor: nVidia with Vulkan support
Location: Around weirdos, I'm the biggest weirdo among them

User error or bug?

Post by Kizoky »

So I'm not entirely sure if it's intentional or not
In languages like C++ I'm able to put code inside switches outside of cases, in ZScript this gets completely ignored

Code: Select all

// example: ('Print!' will not get printed)
void MyFunction()
{
	switch (someinteger)
	{
		Console.Printf("Print!");
		case 1: Stuff2Do(); break;
	}
}
is this considered user error?
User avatar
Player701
 
 
Posts: 1440
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Location: Russia

Re: User error or bug?

Post by Player701 »

I guess that when the switch statement executes, it simply doesn't find a case: to jump to, and skips the entire statement altogether. Note that this is also true for C (and likely C++ too). The only possible usage I see here is to declare a local variable within the scope of the switch statement. Note, however, that if you try to immediately assign a value to it (e.g. int x = 42;), it will not work - and this is not a bug, since the code is effectively unreachable, but the declaration works because the stack space for local variables is allocated upon entering the block.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 48057
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: User error or bug?

Post by Graf Zahl »

No bug here. C's switch statement is not really one of the language's shining moments.
User avatar
Kizoky
Posts: 285
Joined: Mon Nov 14, 2011 9:59 am
Graphics Processor: nVidia with Vulkan support
Location: Around weirdos, I'm the biggest weirdo among them

Re: User error or bug?

Post by Kizoky »

I see, thanks for the clarifications :D

Return to “Scripting”