The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 906 - File: showthread.php PHP 7.2.24-0ubuntu0.18.04.17 (Linux)
File Line Function
/showthread.php 906 errorHandler->error



Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Switch statements with string case values
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#1
Switch statements with string case values

Hey guys, I recently posted in a thread that you could use strings in a case value for switch functions. I was wrong! I have begun to prefer switch functions because they're easy to read and easy to tweak.

Anyways, here's what I thought would work:

AddTimer("timerone", 1, "TimerFunction");
AddTimer("timertwo", 2, "TimerFunction");
AddTimer("timerthree", 3, "TimerFunction");


void TimerFunction(string &in timer)
{
    switch(timer) {
        case timerone:
            //cool stuff
        break;
        case timertwo:
            //cool stuff
        break;
        case timerthree:
            //cool stuff
        break;
    }
}


And here is what I'm currently trying (I get errors on recompiling the script)

void CaveBreathTimer(string &in timer)
{
    switch(CaveBreathStep(timer)) {
        case 1:
            //stuff 1
        break;
        case 2:
            //stuff 2
        break;
        case 3:
            //stuff 3
        break;
    }
}

int CaveBreathStep(string &in stepname)
{
    if(stepname == "cavebreath") return 1;
    if(stepname == "screenshake") return 2;
    if(stepname == "other") return 3;
}

And here's the error I get.

INFO : Compiling int CaveBreathStep(string&in)
ERR : Not all paths return a value

I'm trying to use a subroutine to return an integer which is used by the switch function to determine which case to execute, but the subroutine I wrote is giving me the above error. This way I can avoid using long-winded if statements. If this doesn't work I'll resort to sucking it up and neatly tabulating my if statements.

Also, is there any way to use straight-up use strings as case values in switch functions with AngelScript? I searched online and found a few vague threads that showed C++ code doing it.

I'm stepping into unknown territory, so if you could elaborate on this, please do. This is my first time trying to use return values Smile Thanks

(This post was last modified: 07-22-2011, 11:00 AM by palistov.)
07-22-2011, 10:38 AM
Find


Messages In This Thread
Switch statements with string case values - by palistov - 07-22-2011, 10:38 AM



Users browsing this thread: 1 Guest(s)