Using a string as an array - nice! If I got it right it essentially searches for a "0" character, and then takes the value stored in the one before it, and than (I'm guessing now) replaces it with a "0" when it's done, while filling the string with something non-"0" from the right, right?
But, what happens when there's a "0" as the first character? Are some checks made, or does it just go: (strInput[
0-1] - 48)?
Out of bounds access like that can stop the entire script from executing, maybe even crash the game.
Anyway, I do have 2 suggestions:
- If GetNewSpawnString() is made to take a string& (inout), then it doesn't have to return the string (although it can, for convenience), you can just set it via the reference param, just like GetSetNextSpawnSequential() does. Along the lines of
void A(string& s) { B(s); } // corresponds to GetSetNextSpawnSequential()
void B(string& s) { s = NewString(); } // corr. to GetNewSpawnString()
- You could also avoid all the string-gymnastics if you simply store the index of the current character as a (game-)global variable. Then you just get the index global var, test against the string's length, and get the char, incrementing the index afterwards. (Or, if you're going backwards, start at length() - 1, test if its >0, decrement). This would eliminate the need for having special tokens like "0" in your string.