Skip to content

Help with if/else if?

ZephiriusZephirius Member Posts: 411
edited February 2021 in Builders - Scripting
I don't understand why the else if isn't firing? Argh! *frustrated*
#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

Comments

  • ChreelisterChreelister Member Posts: 30
    I could be wrong on this, I am a novice scripter, but this has gotten me in the past, but try putting 2 equation signs in all the if statements. Like, 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)), 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. :)
  • ZephiriusZephirius Member Posts: 411
    will give it a shot. Thanks for the reply. I know all to well about novice scripting... :)
  • FreshLemonBunFreshLemonBun Member Posts: 909
    edited February 2021
    Looks like what you did was this
    if a caster
    	if has gold
    		take gold
    	else if caster also has a non caster class
    		speak string
    	else
    		speak string
    
    Where as what you want is probably something like this
    if a caster
    	if has gold
    		take gold
    	else
    		speak string
    else if not a caster class
    		speak string
    

    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));
    	}
    }
    
    
  • ForSeriousForSerious Member Posts: 446
    You've got the order wrong.
    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.
    }
    
  • ZephiriusZephirius Member Posts: 411
    Thanks for all the replies guys. Gonna try these out...
    Man, as a beginning coder I just get my **** confused sometimes. Ha! ;)
  • ZephiriusZephirius Member Posts: 411
    All good to go. Awesome. Learned a few things too. Thanks again.
  • ZephiriusZephirius Member Posts: 411
    Hey, check this out. Probably is old news to you scripting vets, bot the program notepad ++ is just what I need for this script, the compiler comes equipped with training wheels!
    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...tuaxtncizc48.png
Sign In or Register to comment.