inaccessible line in switch case? help please o:

You must understand the Game Editor concepts, before post here.

inaccessible line in switch case? help please o:

Postby Game A Gogo » Sun Feb 15, 2009 8:32 pm

Alright, so today I though I might as well start on working a project.. and I though why not my Custon BMP Font loader that I had started long ago. That would be able to load custon BMP fonts with individual letter width (Revolutionary! :) )
But obviously, I need to transform the ASCII letter number to the BMP font char number... So I though I'd use a switch case. But I stumbled upon a problem and I can't figure out what is going wrong.. D:
My script is around 288 lines long, because there are at least 90 letters to convert
And the syntax is correct on all lines (Yes, I checked them all).
and it gives me 90 errors!
each one coming out as "Warning line 288: Unreachable code at line ###" ### being the line number which a "break;" can be found
untitled.gif
Image quality severely decreased due to big image size... and yet my screen is not big enough to show all errors :S

So I noticed that each "Unreachable" code are "break;"... what is wrong?
I'm thinking it might be due to the usage of "return ##"... but I used that before

ps.: Makslane, it would be smart adding "*.txt","*.c" and "*.cpp" extension ;)
Attachments
Char_Map.zip
the 288 line script
(614 Bytes) Downloaded 137 times
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: inaccessible line in switch case? help please o:

Postby skydereign » Sun Feb 15, 2009 8:50 pm

If you are trying to return an int, then the function should be an int function. I only say this because the last error says that it ends in void. I think gameEditor may be confusing the number conversions, but I don't really know how you are doing this. The problem is that break will end the function, as it exits the switch. Since you are trying to return a char, the int does not work for the return of that function, though I think it should, and the function should then be void, as it does not have a return value. But I know the char numbers shouldn't mess up like this.
-EDIT
Okay, if you change it to this, it should work.
Code: Select all
char Char_Map(char Letter_Input)
{
    char RETURN;
    switch(Letter_Input)
    {
        case 33:
        RETURN=1;
        break;
        case 64:
        RETURN=2;
        break;
    }
return(RETURN);
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: inaccessible line in switch case? help please o:

Postby pyrometal » Sun Feb 15, 2009 9:24 pm

Remove all the "break" statements! Return breaks the control flow before "break" can be executed!
SPRITE WARRIOR:
Free, open-source & crossplatform pixel art editor (currently under construction).
User avatar
pyrometal
 
Posts: 706
Joined: Wed Nov 28, 2007 4:07 am
Location: Kingston, ON, Canada
Score: 86 Give a positive score

Re: inaccessible line in switch case? help please o:

Postby Game A Gogo » Sun Feb 15, 2009 10:54 pm

skydereign wrote:If you are trying to return an int, then the function should be an int function. I only say this because the last error says that it ends in void. I think gameEditor may be confusing the number conversions, but I don't really know how you are doing this. The problem is that break will end the function, as it exits the switch. Since you are trying to return a char, the int does not work for the return of that function, though I think it should, and the function should then be void, as it does not have a return value. But I know the char numbers shouldn't mess up like this.
-EDIT
Okay, if you change it to this, it should work.
Code: Select all
char Char_Map(char Letter_Input)
{
    char RETURN;
    switch(Letter_Input)
    {
        case 33:
        RETURN=1;
        break;
        case 64:
        RETURN=2;
        break;
    }
return(RETURN);
}

About the void thing.. at first it was int xD I messed with the code a bit but thx for trying to help, but I'll use Pyro's method instead, so thanks to you as well, pyro
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest