Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Message
| This is a better place for a switch statement:
Quote:
if (ch->class == CLASS_WARRIOR)
send_to_char("Your Evolution choices are Barbarian, Knight, Ranger, or Samurai.\n\r", ch);
else
if (ch->class == CLASS_THIEF)
send_to_char("Your Evolution choices are Assassin, Ninja, or Smuggler.\n\r", ch);
else
if (ch->class == CLASS_MAGE)
send_to_char("Your Evolution choices are Conjurer, Elementalist, Illusionist, or Psionicist.\n\r", ch);
else
if (ch->class == CLASS_CLERIC)
send_to_char("Your Evolution choices are Druid, Monk, or Necromancer.\n\r", ch);
else
if (ch->class == CLASS_CAVALIER)
send_to_char("Your Evolution choices are Paladin or Anti-Paladin.\n\r", ch);
return;
You could use "switch" here like this:
switch (ch->class)
{
case CLASS_WARRIOR:
send_to_char("Your Evolution choices are Barbarian, Knight, Ranger, or Samurai.\n\r", ch);
break;
case CLASS_THIEF:
send_to_char("Your Evolution choices are Assassin, Ninja, or Smuggler.\n\r", ch);
break;
case CLASS_MAGE:
send_to_char("Your Evolution choices are Conjurer, Elementalist, Illusionist, or Psionicist.\n\r", ch);
break;
case CLASS_CLERIC:
send_to_char("Your Evolution choices are Druid, Monk, or Necromancer.\n\r", ch);
break;
case CLASS_CAVALIER:
send_to_char("Your Evolution choices are Paladin or Anti-Paladin.\n\r", ch);
break;
} // end of switch
return;
See how the switch statement makes it look simpler, because you have less "if" tests?
However your code still has problems. See this part ...
for ( iClass = 0; iClass < MAX_PC_CLASS; iClass++ )
{
if (ch->class == CLASS_WARRIOR)
send_to_char("Your Evolution choices are Barbarian, Knight, Ranger, or Samurai.\n\r", ch);
else
if (ch->class == CLASS_THIEF)
send_to_char("Your Evolution choices are Assassin, Ninja, or Smuggler.\n\r", ch);
else
if (ch->class == CLASS_MAGE)
send_to_char("Your Evolution choices are Conjurer, Elementalist, Illusionist, or Psionicist.\n\r", ch);
else
if (ch->class == CLASS_CLERIC)
send_to_char("Your Evolution choices are Druid, Monk, or Necromancer.\n\r", ch);
else
if (ch->class == CLASS_CAVALIER)
send_to_char("Your Evolution choices are Paladin or Anti-Paladin.\n\r", ch);
return; // will return first time through loop
}
Your indenting hides it, but the "return" inside the loop will return the first time through. So why have the loop?
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|