Help with if/else if?
Zephirius
Member Posts: 419
I don't understand why the else if isn't firing? Argh! *frustrated*
This is what your money bought you in case your tuning in: ForSerious, Proleric and anyone else who gives a squirt. Lol
#include "x3_inc_skin"
string sSound = "gui_learnspell";
void main()
{
object oPC = GetPCSpeaker();
if ((GetLevelByClass(CLASS_TYPE_BARD, oPC)>0)||
(GetLevelByClass(CLASS_TYPE_SORCERER, oPC)>0)||
(GetLevelByClass(CLASS_TYPE_WIZARD, oPC)>0)||
(GetLevelByClass(CLASS_TYPE_PALEMASTER, oPC)>0))
{
if (GetGold(oPC) >= 10000)
{
TakeGoldFromCreature(10000, oPC);
FloatingTextStringOnCreature("You've learned to anticipate your opponents attacks! + FEATS - MOBILITY &
HIDE IN PLAIN SIGHT", oPC);
object oSkin = SKIN_SupportGetSkin(oPC);
itemproperty ipAward = ItemPropertyBonusFeat(IP_CONST_FEAT_DODGE);
AddItemProperty(DURATION_TYPE_PERMANENT, ipAward, oSkin);
AssignCommand(oPC, PlaySound(sSound));
}
//Section that doesn't work
else if ((GetLevelByClass(CLASS_TYPE_BARBARIAN, oPC)>0)||
(GetLevelByClass(CLASS_TYPE_CLERIC, oPC)>0)||
(GetLevelByClass(CLASS_TYPE_DRUID, oPC)>0)||
(GetLevelByClass(CLASS_TYPE_FIGHTER, oPC)>0)||
(GetLevelByClass(CLASS_TYPE_MONK, oPC)>0)||
(GetLevelByClass(CLASS_TYPE_PALADIN, oPC)>0)||
(GetLevelByClass(CLASS_TYPE_RANGER, oPC)>0)||
(GetLevelByClass(CLASS_TYPE_ROGUE, oPC)>0)||
(GetLevelByClass(CLASS_TYPE_ASSASSIN, oPC)>0)||
(GetLevelByClass(CLASS_TYPE_BLACKGUARD, oPC)>0)||
(GetLevelByClass(CLASS_TYPE_DIVINECHAMPION, oPC)>0)||
(GetLevelByClass(CLASS_TYPE_DWARVENDEFENDER, oPC)>0)||
(GetLevelByClass(CLASS_TYPE_SHIFTER, oPC)>0)||
(GetLevelByClass(CLASS_TYPE_WEAPON_MASTER, oPC)>0))
{
//just can't get this string to fire
AssignCommand(oPC, FloatingTextStringOnCreature
("This is a wizardly school of some repute! If you want to smash things, Professor Beadle - Bullrush - Timbly's
classroom is just down the hallway!", oPC));
AssignCommand(oPC, PlaySound(sSound));
} // End of broken script
else
{
AssignCommand(oPC, PlaySound(sSound));
AssignCommand(oPC, FloatingTextStringOnCreature
("Insufficient funds! Come back with more coinage.", oPC));
}
}
}
This is what your money bought you in case your tuning in: ForSerious, Proleric and anyone else who gives a squirt. Lol
Post edited by Zephirius on
0
Comments
(GetLevelByClass(CLASS_TYPE_SORCERER, oPC)>0)||
(GetLevelByClass(CLASS_TYPE_WIZARD, oPC)>0)||
(GetLevelByClass(CLASS_TYPE_PALEMASTER, oPC)>0)), should be, if ((GetLevelByClass(CLASS_TYPE_BARD, oPC)>=0)||
(GetLevelByClass(CLASS_TYPE_SORCERER, oPC)>=0)||
(GetLevelByClass(CLASS_TYPE_WIZARD, oPC)>=0)||
(GetLevelByClass(CLASS_TYPE_PALEMASTER, oPC)>=0))
Looks like you did, if (GetGold(oPC) >= 10000), this right. I could be totally wrong too.
Try this
int CheckIsArcane(object oPC) { int is_arcane_caster = FALSE; if ( (GetLevelByClass(CLASS_TYPE_BARD, oPC)>0) || (GetLevelByClass(CLASS_TYPE_SORCERER, oPC)>0) || (GetLevelByClass(CLASS_TYPE_WIZARD, oPC)>0) || (GetLevelByClass(CLASS_TYPE_PALEMASTER, oPC)>0) ) { is_arcane_caster = TRUE; } return is_arcane_caster; } void main() { object oPC = GetPCSpeaker(); //is a caster if (CheckIsCaster(oPC)) { //does have funds if (GetGold(oPC) >= 10000) { TakeGoldFromCreature(10000, oPC); FloatingTextStringOnCreature("You've learned to anticipate your opponents attacks! + FEATS - MOBILITY & HIDE IN PLAIN SIGHT", oPC); object oSkin = SKIN_SupportGetSkin(oPC); itemproperty ipAward = ItemPropertyBonusFeat(IP_CONST_FEAT_DODGE); AddItemProperty(DURATION_TYPE_PERMANENT, ipAward, oSkin); AssignCommand(oPC, PlaySound(sSound)); } //doesn't have funds else { AssignCommand(oPC, PlaySound(sSound)); AssignCommand(oPC, FloatingTextStringOnCreature("Insufficient funds! Come back with more coinage.", oPC)); } } //is not a caster else { AssignCommand(oPC, FloatingTextStringOnCreature("This is a wizardly school of some repute! If you want to smash things, Professor Beadle - Bullrush - Timbly's classroom is just down the hallway!", oPC)); AssignCommand(oPC, PlaySound(sSound)); } }First you check if they have a magic type class. If yes, you check if they have enough gold. If they don't have gold, you check if they have another type class. If they don't have that other type of class, you tell them they don't have enough gold.
If statements don't need to have an else statement. You can do something like:
// This is pseudo code. (will never compile, but the logic is there) if(Has enough money)// if not (else) they don't have enough money. { if(has levels in magic class) else, they have some other type of class { if(doesn't already have the reward feat)// else they already have it. You could tell them that. { give reward feat // If you want to stop checking for other classes at this point, add: return; } } // If you're not looking for all other classes if(has level in some other set of clesses) { do what is needed for this set of classes. } // otherwise, an else statement works perfect here // else will handle all other classes. else { do what is needed for all other classes. } } else { Tell them they don't have the money. }Man, as a beginning coder I just get my **** confused sometimes. Ha!
The line to the far left delineates where one curly brace starts and another stops. Perfect for me when I seem to get them mixed up.
Check attached image...