Programming error.


Questions, Explanations, Howtos

Tomb Titivator

Posts: 799

Joined: Saturday, 23rd February 2013, 22:25

Post Monday, 25th February 2013, 20:25

Programming error.

Kay. I've been trying to make it so mummies get new skills every four levels or so. It doesn't work, and the compiler says that the function's looping or something. Any chance of help?
Here's the first part of the code:
  Code:
case SP_MUMMY:
                if (you.experience_level == 13 || you.experience_level == 26)
                {
                    mpr("You feel more in touch with the powers of death.",
                        MSGCH_INTRINSIC_GAIN);
                }
      
      int mummyspacing = 4;
      int journal = 1;
      if (you.experience_level == mummyspacing*journal){
       
      if (journal == 1){mpr("Allthough much has been lost to the sands of time you still see glimpses of a fleeting past.",
                        MSGCH_INTRINSIC_GAIN);mummyskills();journal = journal + 1;

}
      else if (journal == 2){mpr("You begin to remember more of your hidden past, regaining skills once thought lost.",
                        MSGCH_INTRINSIC_GAIN);mummyskills();journal = journal + 1;}
      else if (journal == 3){mpr("Through flashes and short glimpses, you now know secrets lost to the ages.",
                        MSGCH_INTRINSIC_GAIN);mummyskills();journal = journal + 1;}
      else if (journal == 4){mpr("The ghosts of amnesia are no match for your vast intellect. You know who you are. More importantly, you know who you were.",
                        MSGCH_INTRINSIC_GAIN);mummyskills();journal = journal + 1;}
      else if (journal < 7){mpr("Allthough you allready remember your past, you still gain a flash of insight on your road to ultimate power.",
                        MSGCH_INTRINSIC_GAIN);mummyskills();journal = journal + 1;}
      

}


                if (you.experience_level == 13)  // level 13 for now -- bwr
                {
                    mpr("You can now infuse your body with magic to restore "
                        "decomposition.", MSGCH_INTRINSIC_GAIN);
                }
                break;

And here's the function it's calling:
  Code:
static void mummyskills(){
    int totalweight = 0;
    skill_type result = SK_NONE;
    for (int i = SK_FIRST_SKILL; i < NUM_SKILLS; ++i)
    {
        skill_type s = static_cast<skill_type>(i);
        if (skill_name(s) == NULL || is_useless_skill(s))
            continue;

        if (you.skills[s] < MAX_SKILL_LEVEL)
        {
            // Choosing a skill is likelier if you are somewhat skilled in it.
            const int curweight = 1 + you.skills[s] * (40 - you.skills[s]) * c;
            totalweight += curweight;
            if (x_chance_in_y(curweight, totalweight))
                result = s;
        }
    }
   if (you.skills[result] + 4 < 28){
you.skills[result] = you.skills[result] +4;
}
else{
you.skills[result] = 27;
}
   
}

Ziggurat Zagger

Posts: 3163

Joined: Friday, 6th January 2012, 18:45

Post Monday, 25th February 2013, 20:45

Re: Programming error.

If you're capable of posting the code, you're capable of posting the exact compiler error instead of, "the function's looping or something."

Tomb Titivator

Posts: 799

Joined: Saturday, 23rd February 2013, 22:25

Post Monday, 25th February 2013, 21:10

Re: Programming error.

BlackSheep wrote:If you're capable of posting the code, you're capable of posting the exact compiler error instead of, "the function's looping or something."

Sorry. I'll do that now:
  Code:
player.cc: In function 'void mummyskills()':
player.cc:102: error: 'c' was not declared in this scope
player.cc:3253: Error: Jump to case label
player.cc:3226: error: crosses initialization of 'int journal'
player.cc:3225: error: crosses initialization of 'int mummyspacing'

Then it loops through those three errors for a while, allthough the numbers change. Eventualy it gets to this:
  Code:
player.cc:3147: warning: enumeration value 'SP_NAGA' not handled in switch

It then repeats that for every race in the file appearing after mummies. Then I get
  Code:
make: *** [player.o] Error 1

At that point it just stops and returns to the state before I told it to make.

Ziggurat Zagger

Posts: 3163

Joined: Friday, 6th January 2012, 18:45

Post Monday, 25th February 2013, 21:14

Re: Programming error.

  Code:
const int curweight = 1 + you.skills[s] * (40 - you.skills[s]) * c;

This one is pretty obvious from the error. You never declared what 'c' is.

As for the switch error, you may have missed a closing brace somewhere that's throwing off the rest of the cases. It's hard to read your code the way it's formatted.
Last edited by BlackSheep on Monday, 25th February 2013, 21:20, edited 1 time in total.

Tomb Titivator

Posts: 799

Joined: Saturday, 23rd February 2013, 22:25

Post Monday, 25th February 2013, 21:16

Re: Programming error.

Derp. That's what I get for being lazy and copying and pasting code.

Tomb Titivator

Posts: 799

Joined: Saturday, 23rd February 2013, 22:25

Post Monday, 25th February 2013, 21:20

Re: Programming error.

Horray! Now I have a different bug! This is progress!
Defined c as being 10. Now I get this:
  Code:
player.cc: in function 'void level_change(bool)

Then it just does the same looping thing as before.

Ziggurat Zagger

Posts: 3163

Joined: Friday, 6th January 2012, 18:45

Post Monday, 25th February 2013, 21:24

Re: Programming error.

I don't think you're supposed to declare a variable inside a switch statement. You'll probably have to handle the special skill levels a different way.

For this message the author BlackSheep has received thanks:
khalil

Tomb Titivator

Posts: 799

Joined: Saturday, 23rd February 2013, 22:25

Post Monday, 25th February 2013, 21:31

Re: Programming error.

BlackSheep wrote:I don't think you're supposed to declare a variable inside a switch statement. You'll probably have to handle the special skill levels a different way.

It worked! Thank you! Now my mummies won't suck anymore!

Return to Coding

Who is online

Users browsing this forum: No registered users and 13 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.