Highv Priest wrote...
Though that does bring to question, is the switch/case method less straining for the nwn engine or is the ole' standard if/else if still better?
It really depends on the compiler,
With the default nwn compiler they are about the same. if all of the breaks are placed in the switch they are compiled the same.
If the advanced compiler is used, well, I just don't know if they improved it or not.
But it is inportant to note that if you do not include the breaks the if... else if and the switch are not the same statments. For example, lets say we had a placable that through PC actions get a power level var set on it. we will say that the var could be in the range of 0 - 3. if we wanted the placable to grant the PC effects based on the power level where:
power level 1 would grant: +4 constitution for 10 min
power level 2 would grant : +4 constitution and 2 regenreation for 10 min.
power level 3 would grant : +4 constitution, 2 regeneration and haste for 10 min.
you could write it like this with a case statment:
void main()
{
object oPC = GetLastUsedBy();
int nPowerLevel = GetLocalInt( OBJECT_SELF , "Power" );
effect eEffect;
switch ( nPowerLevel)
{
case 3:
eEffect = EffectHaste();
ApplyEffectToObject( DURATION_TYPE_TEMPORARY,eEffect, oPC,600.0);
case 2:
eEffect = EffectRegenerate( 2, 6.0);
ApplyEffectToObject( DURATION_TYPE_TEMPORARY,eEffect, oPC,600.0);
case 1:
eEffect = EffectAbilityIncrease( ABILITY_CONSTITUTION, 4);
ApplyEffectToObject( DURATION_TYPE_TEMPORARY,eEffect, oPC,600.0);
}
}
since the breaks are not there and the cases are in reverse order, if case 3 happens case 2 and one will also happen. if the power level is 2: only case 2 and 1 will happen. case 1 only case one will happen.
Modifié par Lightfoot8, 17 décembre 2012 - 07:42 .