I understand the memory allocation logic behind using a char array over char*. I don't understand how to implement that in my class constructor. I have attempted to do it for both the mName and the details.
#include "Monster.h"
Monster::Monster(char m[20], byte r,byte h, int i, bool p, char d[25]){
mName[20] = m;
inCombat = false;
initRoll = r;
hp = h;
currhp = hp;
initMod = i;
npc = p;
details[25] = 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();
}
}
and Monster.cpp
#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[25];
Monster(char m[20], byte r,byte h, int i, bool p, char d[25]);
void roll();
void engage();
void kill();
void takeHit(int howHard);
};
#endif
If this is not correct, please include a URL of where I can learn how to do this.