Switch statements with string case values - Printable Version +- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum) +-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html) +--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html) +---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html) +---- Thread: Switch statements with string case values (/thread-9299.html) |
Switch statements with string case values - palistov - 07-22-2011 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: Code: AddTimer("timerone", 1, "TimerFunction"); And here is what I'm currently trying (I get errors on recompiling the script) Code: void CaveBreathTimer(string &in timer) 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 Thanks RE: Switch statements with string case values - DRedshot - 07-22-2011 ok, i was the OP in the other thread, and I think I know how to get it working. I'm not an expert when it comes to scripting, so I cannot separate the integers from the string but you could do this: Code: void func() Code: AddTimer("T1" , 1.0f , "Timer"); edit: I've just reread youre original post, I'm not sure if the above will help you at all. I dont know much about return values myself Another Edit: I think I know the problem in your original code - you haven;'t got an if statement for if the asTimer is not any of the above, maybe else return 0; becausee maybe asTimer="" before the timer is called.. RE: Switch statements with string case values - palistov - 07-22-2011 What you posted is a switch function with integer-type case values, which is the norm with Amnesia scripting. That structure is great for step-wise in-game events, like fainting in a hallway or a cave-in with lots of sounds and such. However, I'm trying to find a way to execute a case based on a timer's name, which isn't simply an integer. I want the timer to be named according to what it does, so I and anyone else reading it can easily follow the flow of the script. Also I'm not sure if that will work, since you're trying to convert a string to an integer in that code. RE: Switch statements with string case values - Ouroboros - 07-22-2011 If you haven't fixed it already, you should try returning 0 at the bottom of the ifs and see what happens. I'm thinking that the function doesn't like not having a return for if none of the ifs are true. RE: Switch statements with string case values - palistov - 07-22-2011 It worked Ouroboros, thanks very much |