Aller au contenu

Photo

probably a dumb question about incrementing ints


  • Veuillez vous connecter pour répondre
7 réponses à ce sujet

#1
Imperator

Imperator
  • Members
  • 64 messages

if(GetHasFeat(FEAT_SPELL_FOCUS_TRANSMUTATION, oSelf))
{
int DC = DC +2;
}
else if(GetHasFeat(FEAT_GREATER_SPELL_FOCUS_TRANSMUTATION, oSelf))
{
int DC = DC +4;
}
else if(GetHasFeat(FEAT_EPIC_SPELL_FOCUS_TRANSMUTATION, oSelf))
{
int DC = DC +6;
}

 

for some reason this isn't incrementing as it should in my script, everything else works in it but this. any idea why?

 

 



#2
meaglyn

meaglyn
  • Members
  • 804 messages

You are redeclaring DC in every code block.  Don't do that. Use "DC = DC +2" not "int DC = DC + 2" assuming you have declared DC earlier once.


  • Wallack et Imperator aiment ceci

#3
Imperator

Imperator
  • Members
  • 64 messages

Thanks for the quick reply, that worked. :D



#4
Tarot Redhand

Tarot Redhand
  • Members
  • 2 669 messages

Also, as the script language used being related to the C programming language, you can save some typing by using the += operator. For example DC += 2 is the same as DC = DC + 2.

 

One other thing, while not strictly necessary, it is probably a good idea to declare all your variables at the start of the function that uses them (it used to be considered easier to maintain).

 

TR


  • Imperator aime ceci

#5
LoA_Tristan

LoA_Tristan
  • Members
  • 40 messages
It probably compiles now at least, but it still won't look for the higher feats. It will only look for GSF if the character lacks SF (note the *else*). But SF is a prerequisite feat for GSF, unless it's granted by an item, so I believe there would be a problem here...

Either reverse the order of checks or make them increment +2?

(reversed, using else)
int DC = 20;
if (GetHasFeat(FEAT_EPIC_SPELL_FOCUS_TRANSMUTATION, oSelf)) DC += 6;
else if (GetHasFeat(FEAT_GREATER_SPELL_FOCUS_TRANSMUTATION, oSelf)) DC += 4;
else if (GetHasFeat(FEAT_SPELL_FOCUS_TRANSMUTATION, oSelf)) DC += 2;
(incremented, no else statements)
int DC = 20;
if (GetHasFeat(FEAT_SPELL_FOCUS_TRANSMUTATION, oSelf)) DC += 2;
if (GetHasFeat(FEAT_GREATER_SPELL_FOCUS_TRANSMUTATION, oSelf)) DC += 2;
if (GetHasFeat(FEAT_EPIC_SPELL_FOCUS_TRANSMUTATION, oSelf)) DC += 2;

  • Tarot Redhand et Imperator aiment ceci

#6
Shadooow

Shadooow
  • Members
  • 4 465 messages

It probably compiles now at least, but it still won't look for the higher feats. It will only look for GSF if the character lacks SF (note the *else*). But SF is a prerequisite feat for GSF, unless it's granted by an item, so I believe there would be a problem here...

int DC = 20;
if (GetHasFeat(FEAT_SPELL_FOCUS_TRANSMUTATION, oSelf)) DC += 2;
if (GetHasFeat(FEAT_GREATER_SPELL_FOCUS_TRANSMUTATION, oSelf)) DC += 2;
if (GetHasFeat(FEAT_EPIC_SPELL_FOCUS_TRANSMUTATION, oSelf)) DC += 2;

this


  • Tarot Redhand, Valgav et Imperator aiment ceci

#7
WhiZard

WhiZard
  • Members
  • 1 204 messages

this

 

I disagree.  The reverse one would work even if used on NPCs that may be given the higher feat and not the prerequisite lower ones.  Another way of doing it is:

 

int nAdjust = 0;
if(GetHasFeat(FEAT_SPELL_FOCUS_TRANSMUTATION, oSelf))
{
nAdjust = 2;
}
if(GetHasFeat(FEAT_GREATER_SPELL_FOCUS_TRANSMUTATION, oSelf))
{
nAdjust = 4;
}
if(GetHasFeat(FEAT_EPIC_SPELL_FOCUS_TRANSMUTATION, oSelf))
{
nAdjust = 6;
}
DC += nAdjust;

  • Imperator aime ceci

#8
Wallack

Wallack
  • Members
  • 121 messages

You are redeclaring DC in every code block.  Don't do that. Use "DC = DC +2" not "int DC = DC + 2" assuming you have declared DC earlier once.

 

I started again scripting and started to create my custom exp tables and system (as my module will go up to level 80) and was getting the too many instructions error when looping through all the party members.

 

My issue? instead of doing oMember = GetNextFaction... I was redeclaring it, object oMember = GetNext ... but the code was so simple that was really hard to identify and to know that. Also in my head it didn't make sense, as the GetNextFactionMember wasn't using oMember but oPlayer that never changed.

 

Just wanted to say that because I spent like an hour to find that ****.