Post: switch case statement not working
03-22-2016, 03:31 PM #1
BullyWiiPlaza
Climbing up the ladder
(adsbygoogle = window.adsbygoogle || []).push({}); Why is the switch case statement not working? Given the following code:
    switch(friendlyFire)
{
case 0:
self printGlobalPlayerAction("No Friendly Fire");
break;

case 1:
self printGlobalPlayerAction("Friendly Fire");
break;

case 2:
self printGlobalPlayerAction("Reflected Friendly Fire");
break;

case 3:
self printGlobalPlayerAction("Shared Friendly Fire");
break;
}

Nothing happens.

If I write the same with if and else statements, it works fine:
    if(friendlyFire == 0)
{
self printGlobalPlayerAction("No Friendly Fire");
}
else if(friendlyFire == 1)
{
self printGlobalPlayerAction("Friendly Fire");
}
else if(friendlyFire == 2)
{
self printGlobalPlayerAction("Reflected Friendly Fire");
}
else if(friendlyFire == 3)
{
self printGlobalPlayerAction("Shared Friendly Fire");
}

Why? I'm using GSC Studio 16.2.15.0 and I'm pretty sure I can write switch case statements correctly.
(adsbygoogle = window.adsbygoogle || []).push({});
03-22-2016, 09:24 PM #2
iRnZ
NextGenUpdate Elite
Originally posted by BullyWiiPlaza View Post



if(friendlyFire == 0)
{
self printGlobalPlayerAction("No Friendly Fire");
friendlyFire = 1;
}
else if(friendlyFire == 1)
{
self printGlobalPlayerAction("Friendly Fire");
friendlyFire = 2;
}
else if(friendlyFire == 2)
{
self printGlobalPlayerAction("Reflected Friendly Fire");
friendlyFire = 3;
}
else if(friendlyFire == 3)
{
self printGlobalPlayerAction("Shared Friendly Fire");
friendlyFire = 0;
}

did u mean that idk what u mean lol but test this ;d
03-22-2016, 09:31 PM #3
Procyon
Gym leader
Originally posted by BullyWiiPlaza View Post
Why is the switch case statement not working? Given the following code:
    switch(friendlyFire)
{
case 0:
self printGlobalPlayerAction("No Friendly Fire");
break;

case 1:
self printGlobalPlayerAction("Friendly Fire");
break;

case 2:
self printGlobalPlayerAction("Reflected Friendly Fire");
break;

case 3:
self printGlobalPlayerAction("Shared Friendly Fire");
break;
}

Nothing happens.

If I write the same with if and else statements, it works fine:
    if(friendlyFire == 0)
{
self printGlobalPlayerAction("No Friendly Fire");
}
else if(friendlyFire == 1)
{
self printGlobalPlayerAction("Friendly Fire");
}
else if(friendlyFire == 2)
{
self printGlobalPlayerAction("Reflected Friendly Fire");
}
else if(friendlyFire == 3)
{
self printGlobalPlayerAction("Shared Friendly Fire");
}

Why? I'm using GSC Studio 16.2.15.0 and I'm pretty sure I can write switch case statements correctly.


I don't think the 'case' statement is supported within gsc. Eek
03-22-2016, 10:04 PM #4
itsSorrow
In my man cave
Originally posted by Procyon View Post
I don't think the 'case' statement is supported within gsc. Eek


they are all supported but for console it doesn't work on PC it does
03-23-2016, 11:25 AM #5
BullyWiiPlaza
Climbing up the ladder
Originally posted by Procyon View Post
I don't think the 'case' statement is supported within gsc. Eek

It is supported. In the original GSCs you can find many of them.
Originally posted by GentleSlugger View Post
they are all supported but for console it doesn't work on PC it does

That might explain it.
03-23-2016, 12:06 PM #6
Procyon
Gym leader
Originally posted by BullyWiiPlaza View Post
It is supported. In the original GSCs you can find many of them.

That might explain it.

Are you setting the variable you actually want to match correctly then?
03-23-2016, 01:45 PM #7
BullyWiiPlaza
Climbing up the ladder
Originally posted by Procyon View Post
Are you setting the variable you actually want to match correctly then?

Obviously yes since the if blocks work. I thought this was not meaningful for the question but here it is:
    friendlyFire = level.friendlyFire; // Get the current value
friendlyFire++; // Increment it since this is meant to be a toggle through values

// Reset the value if it is out of bounds
if(friendlyFire == 4)
{
friendlyFire = 0;
}

// Place conditions here in order to print the state. I would like to use switch case but it's not working correctly

Originally posted by iReZ View Post
did u mean that idk what u mean lol but test this ;d

No, I want to use switch case statements.
03-23-2016, 04:05 PM #8
Originally posted by BullyWiiPlaza View Post
Why is the switch case statement not working? Given the following code:
    switch(friendlyFire)
{
case 0:
self printGlobalPlayerAction("No Friendly Fire");
break;

case 1:
self printGlobalPlayerAction("Friendly Fire");
break;

case 2:
self printGlobalPlayerAction("Reflected Friendly Fire");
break;

case 3:
self printGlobalPlayerAction("Shared Friendly Fire");
break;
}

Nothing happens.

If I write the same with if and else statements, it works fine:
    if(friendlyFire == 0)
{
self printGlobalPlayerAction("No Friendly Fire");
}
else if(friendlyFire == 1)
{
self printGlobalPlayerAction("Friendly Fire");
}
else if(friendlyFire == 2)
{
self printGlobalPlayerAction("Reflected Friendly Fire");
}
else if(friendlyFire == 3)
{
self printGlobalPlayerAction("Shared Friendly Fire");
}

Why? I'm using GSC Studio 16.2.15.0 and I'm pretty sure I can write switch case statements correctly.


It may be the compiler, if you could compile one with the if statement and one with the switch, I can check this for you.
03-23-2016, 05:10 PM #9
jwm614
NextGenUpdate Elite
Originally posted by John View Post
It may be the compiler, if you could compile one with the if statement and one with the switch, I can check this for you.


Yes its the compiler it will only return default on consoles
03-23-2016, 09:02 PM #10
BullyWiiPlaza
Climbing up the ladder
Originally posted by jwm614 View Post
Yes its the compiler it will only return default on consoles

Can or will this be fixed? It would be great since there doesn't seem to be a reason for it

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo