This function is extremely liable to crashing the game if the input is not correct.
As such, I recommend including a return with the TraceAndLog in order to prevent passing invalid data.
I suppose there are two choices here: either return false or return &NullCharacter. I’m using the latter.
Code:
[QUESTS\quests.c]
ref CharacterFromID(string characterID)
{
// PB: Error checking -->
if(characterID == "") characterID = "Boat1234"; // just some random character to prevent error logs
if(sti(GetCharacterIndex(characterID)) == -1)
{
TraceAndLog("ERROR - Missing Character ID: " + characterID);
}
// PB: Error checking <--
return &characters[GetCharacterIndex(characterID)];
}
I suppose there are two choices here: either return false or return &NullCharacter. I’m using the latter.
Last edited: