Author Topic: probably a dumb question about incrementing ints  (Read 875 times)

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0
probably a dumb question about incrementing ints
« on: April 13, 2016, 02:15:37 am »


               

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?


 


 



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
probably a dumb question about incrementing ints
« Reply #1 on: April 13, 2016, 02:19:17 am »


               

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.



               
               

               
            

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0
probably a dumb question about incrementing ints
« Reply #2 on: April 13, 2016, 03:00:44 am »


               

Thanks for the quick reply, that worked. '<img'>



               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
probably a dumb question about incrementing ints
« Reply #3 on: April 13, 2016, 03:34:31 am »


               

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



               
               

               
            

Legacy_LoA_Tristan

  • Jr. Member
  • **
  • Posts: 64
  • Karma: +0/-0
probably a dumb question about incrementing ints
« Reply #4 on: April 14, 2016, 03:44:32 pm »


               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;

               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
probably a dumb question about incrementing ints
« Reply #5 on: April 14, 2016, 04:00:08 pm »


               


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


               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
probably a dumb question about incrementing ints
« Reply #6 on: April 16, 2016, 05:56:09 am »


               


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;

               
               

               
            

Legacy_Wallack

  • Full Member
  • ***
  • Posts: 221
  • Karma: +0/-0
probably a dumb question about incrementing ints
« Reply #7 on: April 18, 2016, 11:02:55 am »


               


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 ****.