Returning inside a switch case, does it go back to the scope of the function, or does it return for the function?
#1

pawn Code:
forward Example(example);
public Example(example)
{
    switch(example)
    {
        case 0:{// stuff}
        case 1:{// stuff}
        case 3:{return 1;}
    }
   
}
Now I understand they are not like C where I have to break them to stop them from calling each other, but if I called Example(3); would that return 1 to the Example function, or to where I called it?
Reply
#2

Why don't try it?

pawn Code:
forward Example(example);
public Example(example)
{
    switch(example)
    {
        case 0:{// stuff}
        case 1:{// stuff}
        case 3:{return 1;}
    }
    return 3;
}
See if in case 3 return 1

or do something like

pawn Code:
forward Example(example);
public Example(example)
{
    new what = 0;
    switch(example)
    {
        case 0:{// stuff}
        case 1:{// stuff}
        case 3:{what = 1;}
    }
    return what;
}
Just debug yourself
Reply
#3

If you return ANYWHERE in a function, the function stops and returns the value. Scope doesn't matter.
Reply
#4

I'm calling the function inside an if statement, if that's what you were asking(if(example(variable) == 1), I kind of knew what returns did, I've been using them obviously, but I wasn't sure how the scope of the return worked, if it went back a layer or if it simply did the equivalent of a break.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)