0

I have no idea how yo fix this issue. it keeps telling me that I have no matching function to call to and it keeps saying no known conversion for argument 1 from 'Npc**' to 'Npc*

specifically, it's saying there's an issue with handleDialogueTwo(&nonplayer); and handleDialogueThree(&nonplayer);

I'm sure this is some dumb fix, but I've been scratching my head over it and shuffling things around for hours now. Please help

void Dungeon::handleRoomWithNpc(Room * room) {
    Npc nonplayer = room->nonplayer.front();
    cout << "Inside, you see a " << nonplayer.name << ".\n";
    string actions[] = {
        "a: Talk to " + nonplayer.name,
        "b: Fight " + nonplayer.name,
        "c: Leave",
        };
    while(true) {
        printActions(3, actions);
        string input;
        cin >> input;
        if (input == "a") {
           handleDialogueOne(&nonplayer);
           return;
        } else if (input == "b") {
            int damage = player.takeDamage(nonplayer.attack);
            cout << nonplayer.name << " hits you for " << damage << " damage! \n";
            if (player.checkIsDead()){
            return;
            };
        } else if (input == "c") {
            player.changeRooms(player.previousRoom);
            enterRoom(player.currentRoom);
            return;
        } else {
            cout << "Wrongo, Bucko.\n";
        }  
    }
}

void Dungeon::handleDialogueOne(Npc * nonplayer) {
    cout << nonplayer->dialogueOne;
    string actions[] = {
            "a: continue",
            "b: die",
            "c: fight",
        };
    while(true) {
        printActions(3, actions);
        string input;
        cin >> input;
        if (input == "a") {
            handleDialogueTwo(&nonplayer);
            return;
        } else if (input == "b") {
            int damage = player.takeDamage(nonplayer->attack);
            cout << nonplayer->name << " hits you for " << damage << " damage! \n";
            if (player.checkIsDead()){
            return;
            }
        } else if (input == "c") {
            int damage = player.takeDamage(nonplayer->attack);
            cout << nonplayer->name << " hits you for " << damage << " damage! \n";
            if (player.checkIsDead()){
            return;
            };
        } else {
            cout << "Wrongo, Bucko!\n";
        }
    }     
}

void Dungeon::handleDialogueTwo(Npc * nonplayer) {
    cout << nonplayer->dialogueTwo;
    string actions[] = {
            "a: continue",
            "b: die",
            "c: fight",
        };
    while(true) {
        printActions(3, actions);
        string input;
        cin >> input;
        if (input == "a") {
            handleDialogueThree(&nonplayer);
            return;
        } else if (input == "b") {
            int damage = player.takeDamage(nonplayer->attack);
            cout << nonplayer->name << " hits you for " << damage << " damage! \n";
            if (player.checkIsDead()){
            return;
            }
        } else if (input == "c") {
            int damage = player.takeDamage(nonplayer->attack);
            cout << nonplayer->name << " hits you for " << damage << " damage! \n";
            if (player.checkIsDead()){
            return;
            };
        } else {
            cout << "Wrongo, Bucko!\n";
        }
    }     
}

void Dungeon::handleDialogueThree(Npc * nonplayer) {
    cout << nonplayer->dialogueThree;
    string actions[] = {
            "a: continue",
            "b: die",
            "c: win",
        };
    while(true) {
        printActions(3, actions);
        string input;
        cin >> input;
        if (input == "a") {
            handleDialogueTwo(&nonplayer);
            return;
        } else if (input == "b") {
            int damage = player.takeDamage(nonplayer->attack);
            cout << nonplayer->name << " hits you for " << damage << " damage! \n";
            if (player.checkIsDead()){
            return;
            };
        } else if (input == "c") {
            nonplayer->currentHealth = 0;
            return;
        } else {
            cout << "Wrongo, Bucko!\n";
        }
    }     
}
  • 2
    The error you get is a very basic (beginners) programming error. However, I see you already have a lot of code! You shouldn't write a lot of code and then start testing. Build a bit, test, build some more, test, etc, etc. Or you could even go the [TDD](https://en.wikipedia.org/wiki/Test-driven_development) way and first write the tests. – JHBonarius Dec 06 '20 at 08:46
  • 2
    Furthermore, the use of `NPC**` indicates you might not be using the right tools. It can probably be replaced by a `std::vector>` (or even just a `std::vector`). – JHBonarius Dec 06 '20 at 08:48
  • It's usually a good idea to test if you get a `nullptr` if your functions accept pointer arguments. If `nullptr` isn't a valid case in your program, take the argument by reference instead to not have to test for `nullptr`. Example: `void Dungeon::handleRoomWithNpc(Room& room)` – Ted Lyngmo Dec 06 '20 at 08:49

1 Answers1

2

The data nonplayer has type Npc * and the type of the callee's argument is also Npc *, so you won't need & in handleDialogueTwo(&nonplayer); and handleDialogueThree(&nonplayer);. Remove them.

MikeCAT
  • 73,922
  • 11
  • 45
  • 70