switch statement bug report
Displaying 1-4 of 4 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Zip

The if/else if format runs fine, the switch crashes verge:
string ActionString(int action)

{
if (action == CMBT_MOVE) return "Move";
else if (action == CMBT_UP) return "Up";
else if (action == CMBT_DOWN) return "Down";
else if (action == CMBT_LEFT) return "Left";
else if (action == CMBT_RIGHT) return "Right";
else if (action == CMBT_WAIT) return "Wait";
else if (action == CMBT_WSHORT) return "Short";
else if (action == CMBT_WLONG) return "Long";
else if (action == CMBT_ATTACK) return "Attack";
/*switch (action)
{
case CMBT_MOVE: return "Move";
case CMBT_UP: return "Up";
case CMBT_DOWN: return "Down";
case CMBT_LEFT: return "Left";
case CMBT_RIGHT: return "Right";
case CMBT_WAIT: return "Wait";
case CMBT_WSHORT: return "Short";
case CMBT_WLONG: return "Long";
case CMBT_ATTACK: return "Attack";
}*/
return "ERROR!";
}

That is all.

Zip

Posted on 2004-06-27 21:23:38

Buckermann

Didn't Vecna mentioned sometime ago that switch statement doesn't works with strings? Or is my memory failing again?

Posted on 2004-06-28 02:38:17

Gayo

It's returns. Returns break switches -- I mentioned it to him ages ago, so I'm sure he'll get to it eventually. In the meantime, declare a local variable, set it in the switch, and return it at the end.

Posted on 2004-06-28 03:14:25

mcgrue

Here's the implementation of gayo's solution.

string ActionString(int action)

{
string s;

s = "ERROR!"

switch (action) {

case CMBT_MOVE: s ="Move";
case CMBT_UP: s ="Up";
case CMBT_DOWN: s ="Down";
case CMBT_LEFT: s ="Left";
case CMBT_RIGHT: s ="Right";
case CMBT_WAIT: s ="Wait";
case CMBT_WSHORT: s ="Short";
case CMBT_WLONG: s ="Long";
case CMBT_ATTACK: s ="Attack";
}

return s;
}

Posted on 2004-06-28 04:25:01


Displaying 1-4 of 4 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.