As suggested, I changed mName to char mName[20], here is my code now:
#include <CircularBuffer.h>
#include "Monster.h"
//Monster(char mName[20] ,bool inCombat, int initRoll,int hp, int initMod)
//.roll() updates initRoll with D20+initMod
//.engage() move to combat
//.kill() remove from combat
//----------------------------------------------------------------------------------------------
//Variables
const int TOME_LENGTH = 12; //the length of the master tome of players and monsters
Monster tome[TOME_LENGTH] = {
{"Thio Ki",1,25,4, false, "PC Human Wizard"},
{"Zenwan",1,27,2, false, "PC Halfling Rogue"},
{"Balkas",1,33,4, false, "PC Elf Monk"},
{"Fire Wolf",1,7,2, true, "AC=13 Flame Bite Melee +4 2d4+1 one fire"},
{"Fire Wolf",1,7,2, true, "AC=13 Flame Bite Melee +4 2d4+1 one fire"},
{"Fire Sprite",1,7,0, true, "AC=9 Melee Bite +4 2d4 one fire"},
{"Son of Ignis",1,10,1, true, "AC=11 Spell Caster Melee +3 1d4"},
{"Son of Ignis",1,10,1, true, "AC=11 Spell Caster Melee +3 1d4"},
{"Son of Ignis",1,10,1, true, "AC=11 Spell Caster Melee +3 1d4"},
{"Son of Ignis",1,10,1, true, "AC=11 Spell Caster Melee +3 1d4"},
{"Son of Ignis",1,10,1, true, "AC=11 Spell Caster Melee +3 1d4"},
{"Aiden",1,14,1, true, "AC=13 Spell Caster Melee +3 1d4"}
};
void setup() {
Serial.begin(9600);
Serial.println("Hello");
multiMonster();
for(byte i = 0; i < TOME_LENGTH; i++){
Serial.println(tome[i].mName);
}
}
void loop() {
}
void multiMonster(){
for(byte active = 0; active < TOME_LENGTH; active++){
CircularBuffer<byte,20> monsterMatch;
monsterMatch.push(active); //Adds the active index to monsterMatch
for(byte compare = 0; compare < TOME_LENGTH; compare++){
if(strcmp(tome[active].mName, tome[compare].mName) == 0 && active != compare){
monsterMatch.push(compare);
}
}
byte apendCounter = 1;
if (monsterMatch.size() > 1){
for(byte u = 0; u < monsterMatch.size(); u++){
char monsterBuffer[4];
sprintf(monsterBuffer, " %d", apendCounter);
strcat(tome[monsterMatch[u]].mName, monsterBuffer);
apendCounter++;
}
}
//for(byte i = 0; i < monsterMatch.size(); i ++){
// Serial.println(tome[active].mName);
// Serial.println(monsterMatch[i]);
//}
monsterMatch.clear();
}
}
and here is the current result:
Hello
1
2
3
4
5
6
7
8
9
10
11
12
For reference here is the revised Monster.h
#ifndef Monster_H
#define Monster_H
#include <Arduino.h>
class Monster{
public:
char mName[20];
bool inCombat;
byte initRoll;
byte currhp;
int hp;
byte initMod;
bool npc;
char* details;
Monster(char mName[20], byte r,byte h, int i, bool p, char* d);
void roll();
void engage();
void kill();
void takeHit(int howHard);
};
#endif
and the Monster.cpp
#include "Monster.h"
Monster::Monster(char mName[20], byte r,byte h, int i, bool p, char* d){
inCombat = false;
initRoll = r;
hp = h;
currhp = hp;
initMod = i;
npc = p;
details = d;
}
void Monster::roll(){
initRoll = random(1,21) + initMod;
}
void Monster::engage(){
inCombat = true;
}
void Monster::kill(){
inCombat = false;
}
void Monster::takeHit(int howHard){
currhp -= howHard;
if (currhp <= 0){
kill();
}
}
So I'm missing something else now, probably related to dealing with Char arrays.