Well can’t say nothing about code efficiency. The gold rule is avert clipping recursive functions when you can fix a couple *for_each for the same result.
The *function_update label I created was supposed to be a sub routine that work analogue to a *setter pattern, if choicescript supported class models.
When I am dealing with values that I’m not sure about quantity or length I usually code a basic interpreter (like a “To_string()” or “To_number()” interpreter) that receives a string and execute a pseudo CRUD (create, read , update, and delete).
with a difference that in this case rather than delete I usually overwrite with a char.
each position of the string can mean something. for example, if I create a string for “hold” my temporary random generated NPCs it would be something like. the [two] first positions for Character_Id, followed by a do_while that “write” a value for each of his status and in the end “write” name for the character and put a “|” symbolizing a end for the loop.
*create tens 0
*create units 0
*create letters ""
*create string "01267Mattew|02335Anna|03542Robert|etc..."
That my interpreter would read:
*temp i 12
*gosub_scene To_number (string[i]) "tens"
*gosub_scene To_number (string[i+1]) "units"
*comment this function read a char and convert it to a number that is written in the
*comment variable whose second parameter named.
*temp char_id 0
*set char_id = ((tens*10)+units)
*gosub_scene To_number (string[i+2]) "units"
*temp char_strenght 0
*set char_strenght units
*gosub_scene To_number (string[i+3]) "units"
*temp char_intelligence 0
*set char_intelligence units
*gosub_scene To_number (string[i+4]) "units"
*temp char_charisma 0
*set char_charisma units
*gosub_scene Do_name_while (string[i+5]) "letters"
*comment Do_name_while is a loop that add a name
*comment from the variable string Letter-by-Letter until
*comment it hit a "|" meaning end of the loop. The result
*comment is kept in the variable "letters"
*temp char_Name ""
*set char_Name letters
In other words. char_id will be ‘02’
Her strength will be 3
Her Intelligence will be 3
Her Charisma will be 5
and Her name will be Anna.
If needed you can add functions that interact with the variable string “searching” by Id and delivering its location. Or functions that change one of the characters attributes in the string (A level up for example)
New characters could be proceduraly created and concatenated to the string. Increment the last id numbe by +1 for each generated character.
I highly discourage you to delete data from the string, but that also may be possible with a function that, given a certain id, it will go to that position in the string and “remove” everything that is not a “|” char.