Author Topic: Error: Not All Control Paths Returned  (Read 413 times)

Legacy_JediMindTrix

  • Sr. Member
  • ****
  • Posts: 383
  • Karma: +0/-0
Error: Not All Control Paths Returned
« on: August 24, 2012, 04:17:48 pm »


               O.O That's a new one too me. Some quick googling didn't really help me out so I am running to here for assistance. I've been forming a library of Custom Effects in an include that is called from another script, to be applied to the PC under certain conditions. It never produced any errors in the include screen, but when I compile a script with it included, it produces the above error.

Below is the include, starting from the line that is causing the issue.

//Library of Weapon Style Effects

//Defender Weapon Style Effect, 3/+20 DR, 2% chance to miss
effect EffectDefenderStyle(object oPC);
effect EffectDefenderStyle(object oPC)
    {
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectMissChance(2, MISS_CHANCE_TYPE_NORMAL), oPC); //2% Miss Chance
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDamageReduction(5, DAMAGE_POWER_PLUS_TWENTY), oPC); //Defender Damage Reduction, 5/+20
    }

//Fencer Weapon Style Effect, +1d4 Piercing Damage, +2 Dodge Bonus, -5 Discipline
effect EffectFencerStyle(object oPC);
effect EffectFencerStyle(object oPC)
    {
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectACIncrease(2, AC_DODGE_BONUS), oPC); //Fencer AC increase
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDamageIncrease(d4(1), DAMAGE_TYPE_PIERCING), oPC); //+1d4 Piercing Damage
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectSkillDecrease(SKILL_DISCIPLINE, 5), oPC); //-5 Discipline Penalty
    }

//Powerful Swings Style Effect, +1d6 Bludgeoning Damage, -2 Tumble, -1 Dodge AC
effect EffectPowerfulStyle(object oPC);
effect EffectPowerfulStyle(object oPC)
    {
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectACDecrease(1, AC_DODGE_BONUS), oPC); //AC Decrease
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDamageIncrease(d6(1), DAMAGE_TYPE_BLUDGEONING), oPC); //+1d6 bludgeoning bonus
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectSkillDecrease(SKILL_TUMBLE, 2), oPC); //-2 Tumble
    }

//Twin Blades Style Effect, +2 to off-hand attack bonus, -3 AC
effect EffectTwinBladesStyle(object oPC);
effect EffectTwinBladesStyle(object oPC)
    {
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectACDecrease(3, AC_DODGE_BONUS), oPC);
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectAttackIncrease(2, ATTACK_BONUS_OFFHAND), oPC);
    }

//Sun Fist unarmed style, +1d4 Bludgeoning
effect EffectSunFistStyle(object oPC);
effect EffectSunFistStyle(object oPC)
    {
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDamageIncrease(d4(1), DAMAGE_TYPE_BLUDGEONING), oPC); //+1d4 Bludgeoning bonus
    }

//Tiger Fang unarmed style, +1d6 slashing
effect EffectTigerFangStyle(object oPC);
effect EffectTigerFangStyle(object oPC)
    {
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDamageIncrease(d6(1), DAMAGE_TYPE_SLASHING), oPC); //+1d6 slashing bonus
    }

//Dragon Palm unarmed style, +1d6 magical bonus (aka chi)
effect EffectDragonPalmStyle(object oPC);
effect EffectDragonPalmStyle(object oPC)
    {
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDamageIncrease(d6(1), DAMAGE_TYPE_MAGICAL), oPC); //+1d6 magical "chi" bonus
    }

//Ken-Seijin style, +2 Attack Bonus, +1d8 Slashing Bonus
effect EffectKenSeijinStyle(object oPC);
effect EffectKenSeijinStyle(object oPC)
    {
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDamageIncrease(d8(1), DAMAGE_TYPE_SLASHING), oPC); //+1d8 slashing damange bonus
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectAttackIncrease(2, ATTACK_BONUS_MISC), oPC); //+2 Attack Bonus
    }

//Singing Sword style, +2 Attack Bonus, +1d6 Magical Bonus
effect EffectSingingSwordStyle(object oPC);
effect EffectSingingSwordStyle(object oPC)
    {
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDamageIncrease(d6(1), DAMAGE_TYPE_MAGICAL), oPC); //+1d6 Magical Bonus
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectAttackIncrease(2, ATTACK_BONUS_MISC), oPC); //+2 Attack Bonus
    }

//Bear Claw style, +1d6 Magical Bonus, +1d6 Slashing Bonus
effect EffectBearClawStyle(object oPC);
effect EffectBearClawStyle(object oPC)
    {
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDamageIncrease(d6(1), DAMAGE_TYPE_MAGICAL), oPC); //+1d6 Magical Bonus
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDamageIncrease(d6(1), DAMAGE_TYPE_SLASHING), oPC); //+1d6 Slashing Bonus
    }

//Should theoretically remove any previously applied effects from weapon styles.
void RemovePreviousStyleEffects(object oPC);
void RemovePreviousStyleEffects(object oPC)
 {
 RemoveEffect(oPC, EffectDefenderStyle());     //Defender Style
 RemoveEffect(oPC, EffectFencerStyle());       //Fencer Style
 RemoveEffect(oPC, EffectPowerfulStyle());     //Powerful Swings style
 RemoveEffect(oPC, EffectTwinBladesStyle());   //Twin Blades style
 RemoveEffect(oPC, EffectSunFistStyle());      //Sun Fist style
 RemoveEffect(oPC, EffectDragonPalmStyle());   //Dragon Palm style
 RemoveEffect(oPC, EffectTigerFangStyle());    //Tiger Fang style
 RemoveEffect(oPC, EffectKenSeijinStyle());    //Ken-Seijin Style
 RemoveEffect(oPC, EffectSingingSwordStyle()); //Singing Sword Style
 RemoveEffect(oPC, EffectBearClawStyle());     //Bear Claw Style
 }

               
               

               
            

Legacy_acomputerdood

  • Sr. Member
  • ****
  • Posts: 378
  • Karma: +0/-0
Error: Not All Control Paths Returned
« Reply #1 on: August 24, 2012, 04:27:53 pm »


               that error means you have a path of execution that doesn't lead to a return.  the most common example is if you had:


int foo(){
int i = d6();
if(i < 3){
return 1;
}else{
//do something else
}
}

you can see that in the else block control path, it doesn't actually return.

here's a lexicon page that might help:
http://beta.nwnlexic..._Error_Messages


specifically to you, it's because all of your functions claim to return an effect, but there is no return statement.  it can likely be fixed by changing their return values to void.  or you have to figure out if you actually wanted an effect returned and then do that.

again, for example, you have:

effect EffectDefenderStyle(object oPC){
ApplyEffect();
...
}

nothing in your code block actually returns the effect that the function declared it would.

since you're applying the effects to the PC in this include function, i'm going to assume you meant:


void EffectDefenderStyle(object oPC){
ApplyEffect()
...
}

               
               

               


                     Modifié par acomputerdood, 24 août 2012 - 04:03 .
                     
                  


            

Legacy_JediMindTrix

  • Sr. Member
  • ****
  • Posts: 383
  • Karma: +0/-0
Error: Not All Control Paths Returned
« Reply #2 on: August 24, 2012, 04:46:27 pm »


               That is indeed what I meant to do (and it fixed that particular error).
I am now getting a declaration doesn't match parameters error from
//Should theoretically remove any previously applied effects from weapon styles.
void RemovePreviousStyleEffects(object oPC);
void RemovePreviousStyleEffects(object oPC)
 {
 RemoveEffect(oPC, EffectDefenderStyle());     //Defender Style
 RemoveEffect(oPC, EffectFencerStyle());       //Fencer Style
 RemoveEffect(oPC, EffectPowerfulStyle());     //Powerful Swings style
 RemoveEffect(oPC, EffectTwinBladesStyle());   //Twin Blades style
 RemoveEffect(oPC, EffectSunFistStyle());      //Sun Fist style
 RemoveEffect(oPC, EffectDragonPalmStyle());   //Dragon Palm style
 RemoveEffect(oPC, EffectTigerFangStyle());    //Tiger Fang style
 RemoveEffect(oPC, EffectKenSeijinStyle());    //Ken-Seijin Style
 RemoveEffect(oPC, EffectSingingSwordStyle()); //Singing Sword Style
 RemoveEffect(oPC, EffectBearClawStyle());     //Bear Claw Style
 }

Starting at the first RemoveEffect. I'm not sure why, I don't see anything wrong with it. >.<
               
               

               


                     Modifié par NineCoronas2021, 24 août 2012 - 03:46 .
                     
                  


            

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Error: Not All Control Paths Returned
« Reply #3 on: August 24, 2012, 04:57:38 pm »


               Your error is because EffectDefenderStyle() doesn't return an effect but is a void...So you can't use it in a RemoveEffect function...

Edit: To remove effects on a PC, you must set up a while loop to check for every effect the PC currently has and remove those you want
               
               

               


                     Modifié par Krevett, 24 août 2012 - 03:59 .
                     
                  


            

Legacy_acomputerdood

  • Sr. Member
  • ****
  • Posts: 378
  • Karma: +0/-0
Error: Not All Control Paths Returned
« Reply #4 on: August 24, 2012, 05:02:53 pm »


               yeah, i hadn't carefully read all of your code to see what my suggestion would do.  your RemovePreviousStyleEffects() function expects EffectDefenderStyle() and all those to return effects to it.  since they're now returning void, RemoveEffect() is failing.

you'll likely have to set up helper functions that do void RemoveEffectDefenderStyle() and then manually remove the effects that EffectDefenderStyle() added.  for completeness then, i would change EffectDefenderStyle() to "AddEffectDefenderStyle()" just to be a little more clear about what's going on.  but i digress.

once you have your RemoveEffect* helper functions done, then you can just run down the list of them in RemovePreviousStyleEffects().
               
               

               
            

Legacy_JediMindTrix

  • Sr. Member
  • ****
  • Posts: 383
  • Karma: +0/-0
Error: Not All Control Paths Returned
« Reply #5 on: August 24, 2012, 05:20:27 pm »


               There is no way around that? >.<

I'm not sure I understand what you mean by helper functions, could you provide an example?
               
               

               
            

Legacy_JediMindTrix

  • Sr. Member
  • ****
  • Posts: 383
  • Karma: +0/-0
Error: Not All Control Paths Returned
« Reply #6 on: August 24, 2012, 05:32:49 pm »


               I think I understand what you're saying.
//Remove Defender Weapon Style Effect, 3/+20 DR, 2% chance to miss
void RemoveDefenderStyle(object oPC);
void RemoveDefenderStyle(object oPC)
    {
    RemoveEffect(oPC, EffectMissChance()); //2% Miss Chance
    RemoveEffect(oPC, EffectDamageReduction()); //Defender Damage Reduction, 5/+20
    }

I could implement a series of functions such as that, then in RemoveWeaponStyles list those 'helper functions'.

It's a good idea, but what happens if this script is called and something such as Stoneskin is active on the player, it's going to strip those effects from them too, isn't it?

Which is why I wanted those specific effects defined as unique effects >.<
               
               

               
            

Legacy_acomputerdood

  • Sr. Member
  • ****
  • Posts: 378
  • Karma: +0/-0
Error: Not All Control Paths Returned
« Reply #7 on: August 24, 2012, 05:37:24 pm »


               yeah, that should work i think.  unless i'm wrong about how removing effects from creatures works.


to answer your second question, then you'd have to go back to where you originally were and have your EffectDefenderStyle() and keep them as returning effects instead of void.  but since that's the case, instead of applying the affect to the PC inside the function, it would just return the effect you generated there.  the problem with that is you're creating two or more distinct effects in the functions and there's no way to return them both.
               
               

               


                     Modifié par acomputerdood, 24 août 2012 - 04:39 .
                     
                  


            

Legacy_JediMindTrix

  • Sr. Member
  • ****
  • Posts: 383
  • Karma: +0/-0
Error: Not All Control Paths Returned
« Reply #8 on: August 24, 2012, 05:39:14 pm »


               It caused a "declaration does not match parameter" error also.

I think the secret to this is defining custom effects; how does one do this?
               
               

               
            

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Error: Not All Control Paths Returned
« Reply #9 on: August 24, 2012, 05:45:39 pm »


               This is how you should preoceed to remove effects from a creature: the example below removes all negative status effects from oTarget

effect eBad = GetFirstEffect(oTarget);
int nType;
while(GetIsEffectValid(eBad))
{
nType = GetEffectType(eBad);
if (nType == EFFECT_TYPE_ABILITY_DECREASE ||
    nType == EFFECT_TYPE_AC_DECREASE ||
    nType == EFFECT_TYPE_ATTACK_DECREASE ||
    nType == EFFECT_TYPE_DAMAGE_DECREASE ||
    nType == EFFECT_TYPE_DAMAGE_IMMUNITY_DECREASE ||
    nType == EFFECT_TYPE_SAVING_THROW_DECREASE ||
    nType == EFFECT_TYPE_SPELL_RESISTANCE_DECREASE ||
    nType == EFFECT_TYPE_SKILL_DECREASE ||
    nType == EFFECT_TYPE_BLINDNESS ||
    nType == EFFECT_TYPE_DEAF ||
    nType == EFFECT_TYPE_CURSE ||
    nType == EFFECT_TYPE_DISEASE ||
    nType == EFFECT_TYPE_POISON ||
    nType == EFFECT_TYPE_PARALYZE ||
    nType == EFFECT_TYPE_NEGATIVELEVEL)
RemoveEffect(oTarget, eBad);
eBad = GetNextEffect(oTarget);
}


So in your example you could check for nType == EFFECT_TYPE_DAMAGE_REDUCTION or nType == EFFECT_TYPE_MISS_CHANCE
               
               

               


                     Modifié par Krevett, 24 août 2012 - 04:47 .
                     
                  


            

Legacy_JediMindTrix

  • Sr. Member
  • ****
  • Posts: 383
  • Karma: +0/-0
Error: Not All Control Paths Returned
« Reply #10 on: August 24, 2012, 05:54:53 pm »


               But how do I allow for effects conferred by spells or other items? These methods don't discriminate between effects given by spells and effects given by the weapon styles.
               
               

               


                     Modifié par NineCoronas2021, 24 août 2012 - 04:55 .
                     
                  


            

Legacy_the.gray.fox

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Error: Not All Control Paths Returned
« Reply #11 on: August 24, 2012, 06:12:36 pm »


               You can use GetEffectCreator() to query for the object that created the effect in exam. Look it up in the Lexicon.

Effects created from a spell will have for creator the very spellcaster creature (you cast a spell -> you are the creator of all effects applied by that spell).

Effects created by your custom weapon styles will probably have for creator the Module itself, or some other object that is not a creature anyway -- an Area too can be a valid effect creator, and you can take advantage of it to discriminate without flaw between its effects and everything else.


-fox
               
               

               


                     Modifié par the.gray.fox, 24 août 2012 - 05:17 .
                     
                  


            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Error: Not All Control Paths Returned
« Reply #12 on: August 24, 2012, 10:24:02 pm »


               Since you're going to be applying the effects with usable feats, you can loop through the effects and remove the ones that correspond to the SpellID of the feat:

void RemoveEffectsBySpellID(object oTarget, int nSpellID)
{
    effect eEffect = GetFirstEffect(oTarget);
    while (GetIsEffectValid(eEffect))
    {
        if (GetEffectSpellId(eEffect) == nSpellID)
            RemoveEffect(oTarget, eEffect);
       
        eEffect = GetNextEffect(oTarget);
    }
}

So, for example, if the SpellID for your feat that set the style is 657, you would do this:

RemoveEffectsBySpellID(oPC, 657);

               
               

               


                     Modifié par Squatting Monk, 24 août 2012 - 09:25 .