Oooh, I do! I get it now!
Yes, that CAN be quite a handful, but there are ways of doing it. ^^ I’m sure my ways are not the best, but here it goes!
Two of the ways I can think of right now are through the STORAGE and through STRUCTURES. Both can be used together, actually.
Storage Only:
In the “Read from storage” actions, you can use variables and expressions to assign values to the “Storage name” and “Group” fields. Through that, you can randomize what you get.
This being said, the way to do this would be to write the possible names you want inside a storage file, and give a NUMBER VALUE to the group each name is stored in. This is very important - a number value.
Make a scene variable, and do = RandomInRange(1,20) to the value of said variable. The last number should be the total number of groups you have in the storage - the total number of possible names you have. Let’s call that variable “GenerateName”.
Then, when you’re creating the Character object, call the “Read a text from storage” action and assign the expression VariableString(GenerateName) to the “Group” field.
The variable will return a random number, from 1 to 20 (or whatever limit you set to it), and the group corresponding to that number will be read.
Then, just assign that value to another variable - let’s call it “NameGenerated” - and assign it to the object.
This can be done with names, stats and whatever else you want. ^^;
Structure Variables
This one is quite similar.
Make a STRUCTURE and call it “Names”. Then, make Child Variables - numbered, starting from 0. Assign a number to each child variable. By the end of it, if you have 20 names, you should have 20 child variables inside the “Names” structure, each of them holding a number in their string. As we started with 0, the last child variable should be numbered “19”.
Then, make another scene variable - NOT inside the structure - and call it “RandomName”. This will be the variable we will use to generate a random value.
Now we are ready to randomly generate the name. We can do:
// Getting a Random Number Value //
If the timer "Randomize" is greater than 1 seconds
Trigger Once
do = Random(19) to scene variable "RandomName".
reset the timer "Randomize"
// Generating a Random Name From The Structure //
If the text of variable "Name" of Character = "" (empty)
do = VariableString(Names[VariableString(RandomName)]) to the text of variable "Name" of Character
This way, you will pick a random child variable from the “Names” structure, and assign its string to the “Name” variable of the Character. The conditions prevent multiple names from being assigned to the same character.
Making It Easier - Combining Structures and Storage
You can make all of this much easier by SAVING the Structure variable into the Storage, and reading it from the Storage whenever you want.
Structures are a bit tricker to save, so what we have to do is:
// Save //
If scene variable "Save" = 1
write ToJSON(Names) in "Names" of storage "A"
( Remember to pick the "Write a text" action, not "Write a value". )
// Load //
If "Names" exists in storage "A"
read "Names" from storage "A" and store as text in "NamesJSON"
parse JSON string VariableString(NamesJSON) and store it into variable Names
This way, the Structure will be written into the storage as a JSON string and can be loaded back into the game as a Structure anytime a character needs to be created again. ^^
If you want to store these values in the local storage from the beginning, maybe keep them in the first scene of the game and save them automatically into the local storage when the game starts? I’m sure there are better ways of doing it, but this is what I can think of right now!
I hope this helps!