I'm brand new to C++, and I've been trying to make a simple game. I want a system for status effects the player can apply to the enemy, so I made an array of strings that can hold 5 elements, like "burning" or "poisoned" etc. When I tested this, however, it seemed to always apply the status effect (in this case, burning) to the first AND second status "slot". I want it to only apply to my first empty slot. I took this portion of the code out and expanded it from a for loop to an if statement, and this time I outputted the value of statusEffect and it gave me 0x1000020f0. I have no idea what that even is.
Here's my code, I'm working on Xcode if that helps.
int statusEffectDuration[5] = {0, 0, 0, 0, 0};
string statusEffect[5] = {"NONE", "NONE", "NONE", "NONE", "NONE"};
// Function for applying status effects
void applyStatusEffect(string appliedEffect, int statusDuration) {
if (statusEffect[0] == "NONE") { // If first status effect is nothing then changes first status to "EFFECT"
statusEffect[0] = appliedEffect;
statusEffectDuration[0] = statusDuration;
}
else if (statusEffect[1] == "NONE") { // Same as first, but if second status is nothing then changes second status to "EFFECT"
statusEffect[1] = appliedEffect;
statusEffectDuration[1] = statusDuration;
}
else if (statusEffect[2] == "NONE") { // Third
statusEffect[2] = appliedEffect;
statusEffectDuration[2] = statusDuration;
}
else if (statusEffect[3] == "NONE") { // Fourth
statusEffect[3] = appliedEffect;
statusEffectDuration[3] = statusDuration;
}
else if (statusEffect[4] == "NONE") { // Fifth
statusEffect[4] = appliedEffect;
statusEffectDuration[4] = statusDuration;
}
else if (statusEffect[5] == "NONE") { // Sixth
statusEffect[5] = appliedEffect;
statusEffectDuration[5] = statusDuration;
}
}
int main() {
applyStatusEffect("EFFECT", 5); // "EFFECT" is the effect that is given, 5 is duration of effect
// Displays status effect and effect duration
cout << statusEffect; // Displays 0x1000020f0
cout << "\n";
cout << statusEffectDuration; // Displays 0x1000020f0
return 0;
}
EDIT: I'm dumb. I was printing the address. But the problem with it giving the value to the first two empty spaces instead of one is the original reason I posted this.