Slot system help

I am working with another coder to try to get our game demo finished, however, we are running into some problems. One problem is that we have random characters that have randomized traits, names, etc. and we are building a slot system for these randomized characters. For several areas, we managed to be fine with only around 5 slots for these characters. But for others…we need a more efficient system that can save these characters in higher quantities.
For example, you can only have five lovers, but you can have twenty children from different mothers. We need a way to save those twenty randomized children with all their traits and names and everything.

What are your ideas for an efficient slot system that can hold so many interactable characters? How would you design something like this?

Does the number of the childrens caps or can go unlimited?

If former, it’s more manageable to just write something like *create children1 up to 20. If latter, I’d put their data into some kind of a seed code, accessed by another subroutines to fetch the children and their traits.

How many traits total?

1 Like

Humm. It can be done? maybe…

*comment === Children slots ====
*create Children_1 false
*create Children_1_name "Insert name here"
*create Children_1_age 0
*create Children_1_attribute "unknown"
*create Children_1_value 13

*create Children_2 false
*create Children_2_name "Insert name here"
*create Children_2_age 0
*create Children_2_attribute "unknown"
*create Children_2_value 13

*create Children_3 false
*create Children_3_name "Insert name here"
*create Children_3_age 0
*create Children_3_attribute "unknown"
*create Children_3_value 13

*create Children_4 false

*comment === etc... ====

*create Children_x false
*create Children_x_name "Insert name here"
*create Children_x_age 0
*create Children_x_attribute "unknown"
*create Children_x_value 13

So we write something like This:

*set Children_2 true
*gosub function_update  "2" 16 "value"


then in the other scene

*label function_update
*temp i param_1
*temp n param_2
*temp key param_3
*comment === key can be equals to "age","name","value" or attribute

*if (Children[i] = true )
  *set Children[i][key] n
  The new value is: ${Children[i][key]}

like that?

Let’s say 30

1 Like

The highest we would go is maybe 100.

If you’re 100% sure to not having children beyond 100, @Nahim_Kerman’s would be the most simplest, the most manageable without trying to do anything fancy. CS games aren’t taxing games, so I figure it’d be fine even if you have 10k variables.

However, if you have existing system set up to load all the chars and their traits in your game, and wanted to expand that to include [children]-type character, it would be a different journey to take. I think it’d be helpful if you can share the code so we can see and try to get a feel on how to accomodate the children chars. Your coding partner is probably more savvy about this, so they’re welcome to directly jump in to the convo.

1 Like

I’d argue that would be an overkill. If you take into account mobile-based devices with low clock rates which a lot of people use to read cs games and single threaded javascript that the thing will run in, I would bet 10k variables becomes a substantial hurdle that will produce a substantial lag.

1 Like

The variables are mostly going to the memory. If we’re talking about subroutines, it’ll be different.

Playing the game for the first time/restarting could take a while in either case, I think.

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.

For example:

*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.

1 Like

If you can have that many Kids, why Not Just Roll them randomly by birth? You have to take Tracks of who you Mate, but everything else could Just be random


Memory is not static though. And js runtimes on phones are very eager to start GC (which will pause main javascript loop until it finishes, I might add) when it finds out half or more of your 10k vars are not being referenced often. Then the slowdowns will start, imo.

Yeah, restarts/first starts will be doubly diabolic in this case…


Are you sure that having a hundred kids is a mechanic that would work well with a Choicescript game? You might be able to force the engine to keep track of that many randomised variables, but you won’t be able to make the player keep them all straight in his head.

What I’m trying to say is that with that number of children your only option would be pretty much to treat them as pets, as opposed to fleshed out characters that you can interact individually with. As this is a very story-driven format, perhaps people would prefer to have fewer kids, but be able to get to know them?


I understand what you are saying about story driven content. The only problem with minimizing the number of children is that many other life simulators allow you to have up to or over this number. Since my game is inspired by life simulators…I enjoyed that aspect. Such as a the 100 baby challenge in The Sims or as an achievement in life simulation apps. I am not opposed to making this number smaller if we need to. It is just in the air right now.

(This is also to check I’m picking up the coding - So a confirmation would be great :slight_smile: )

If you mean to persist a child, once its born, then @Nahim_Kerman has an good example solution.

You’d have to setup all the variables in startup with *create, so you’d have to set a maximum number of kids that you want, wouldn’t you?

Random names - that are sensible - would mean having a string (like Nahim’s) to pick from (using a rand “key”), you could use another long-string to store which ones had already been used.

You could use *rand for any int, str or whatever variables, rather than store them in a string, making a bit less work for you to create.

A *gosub_scene could be used to create each one - on the fly - when you need it (see Nahim’s code) and another to update their stats as time progresses.

I’ve no idea how much of a tax on the system it would be … Phones … But some testing - of just this as a function? - should be possible on a few phones by friends to give you an idea?