Keep getting an error report

This is a discussion on Keep getting an error report within the Game Programming forums, part of the General Programming Boards category; Recently in the game im making I added in a shop function. First I added in "Offensive Items" and "Defensive ...

  1. #1
    Codigious FingerPrint's Avatar
    Join Date
    Mar 2006
    Posts
    60

    Unhappy Keep getting an error report

    Recently in the game im making I added in a shop function. First I added in "Offensive Items" and "Defensive Items" options. All the items you could buy in there worked just fine. Then I added in "Potions" as an option and now im having some troubles.

    When you select the potions option it loads all the potions and their prices and everything just like it should. After selecting a potion it should open addPotion(). Well, it opens addPotion() but the only thing that appears, thats supposed to, is "Select a potion slot:". Which is where you would pick 1 of three slots to store the potion so you can access it in battle.

    Yet when you pick your potion it opens addPotion(), says to pick a slot then I get an error report. The error report pops up and says the program needs to close. Ive tried my game on about 10 different computers and I get the same problem on all of them.

    Just from that can anyone tell me why I may be getting this problem? And a possible way to fix it.
    Code:
    /* ------------------------------------------------------------------*/
                               // INSERT CODE HERE
    /* ------------------------------------------------------------------*/

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,062
    Show your addPotion function. There is clearly an error in it. Also, give more details on what the error says. Is it a segmentation fault or what?
    Sent from my iPadŽ

  3. #3
    Codigious FingerPrint's Avatar
    Join Date
    Mar 2006
    Posts
    60
    Ok, here is the code for the addPotion().

    Code:
    void addPotion( int cost, char* potionName, int hp, int pot){
         if(pot == 1){
                if(chr.gold > cost || chr.gold == cost){
                potionLoop = 1;
                while(potionLoop == 1){
                     cout << " Choose a potion slot: \n\n";
                     Sleep(1000);
                     if(strcmp(chr.offpotionName1, "-")==0){
                     cout << " -empty-\n\n";
                     }
                     else{
                          cout << " 1. " << chr.offpotionName1 << "\n";
                          }
                     if(strcmp(chr.offpotionName2, "-")==0){
                     cout << " -empty-\n\n";
                     }
                     else{
                          cout << " 2. " << chr.offpotionName2 << "\n";
                          }
                     if(strcmp(chr.offpotionName3, "-")==0){
                     cout << " -empty-\n\n";
                     }
                     else{
                          cout << " 3. " << chr.offpotionName3 << "\n";
                          }
                cout << " I don't want this potion.\n\n";
                cin >> slotOption;
                Sleep(750);
                switch(slotOption){
                     case 1:
                          chr.gold = chr.gold - cost;
                          chr.offpotionName1 = potionName;
                          chr.offpotionUsed1 = 0;
                          chr.offpotionHP1 = hp;
                          cout << "\n\n The potion " << potionName << " was successfully added to Poion Slot 1.\n\n";
                          Sleep(1000);
                          potionLoop = 0;
                          break;
                     case 2:
                          chr.gold = chr.gold - cost;
                          chr.offpotionName2 = potionName;
                          chr.offpotionUsed2 = 0;
                          chr.offpotionHP2 = hp;
                          cout << "\n\n The potion " << potionName << " was successfully added to Potion Slot 2.\n\n";
                          Sleep(1000);
                          potionLoop = 0;
                          break;
                     case 3:
                          chr.gold = chr.gold - cost;
                          chr.offpotionName3 = potionName;
                          chr.offpotionUsed3 = 0;
                          chr.offpotionHP3 = hp;
                          cout << "\n\n The potion " << potionName << " was successfully added to Potion Slot 3.\n\n";
                          Sleep(1000);
                          potionLoop = 0;
                          break;
                     case 4:
                          cout << " You leave the shop.\n\n";
                          Sleep(1500);
                          potionLoop = 0;
                          break;
                     default:
                             cout << " Something went wrong...try again.\n\n";
                             Sleep(1500);
                             }
                             }//End WHILE
                             }
                else{
                     cout << " You don't have that much money.\n\n";
                     Sleep(1500);
                     potionLoop = 0;
                     }
                     }
                     }
    Im not really sure what to say about the error report. ITs one of the windows ones that pops up and just says "LoC has encountered a porblem and needs to close. Sorry for your inconvenience." I dont get those often so im not really sure what else to tell you about it.
    Code:
    /* ------------------------------------------------------------------*/
                               // INSERT CODE HERE
    /* ------------------------------------------------------------------*/

  4. #4
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    498
    Sounds like a GP fault. I didn't really have time to read through your entire code, but are you sure that your pointers are being managed properly? Try going through it with a debugger.

  5. #5
    Codigious FingerPrint's Avatar
    Join Date
    Mar 2006
    Posts
    60
    I downloaded the GDB program and I cant figure out how it works. Out of all the folders included in its download, I cant seem to find the client itself. How do I open it so I can use it?
    Code:
    /* ------------------------------------------------------------------*/
                               // INSERT CODE HERE
    /* ------------------------------------------------------------------*/

  6. #6
    Registered User
    Join Date
    Jul 2006
    Posts
    2
    chr.offpotionName1 = potionName;
    You're trying to directly assign a string (char *) to another. This isn't possible in C++. Instead, try looking up the "strcpy" function via Google (or better yet, look into std::string).

    Code:
    strcpy(char *stringToCopyTo, const char *stringToCopyFrom);

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21