Managing randomly created characters.

Galdon2004

  • *
  • Posts: 318
I am working on a new concept which would be a management simulator, so characters would be added to the game in-engine. A normal global attribute profile would not work well in this case, as once I ran out of sets of global attributes, I would no longer be able to have the game create characters.

I do, however, need to be able to save the randomly created characters appearances and stats so they are consistent once created. I had considered making a list to handle it, so whenever a new character is added, it could add it's set of attributes to the list, but I don't see an intuitive way to make a list of lists as the stencylpedia mentions in passing, and I am not sure if making an individual list for each attribute would be manageable.

Has anyone else made something similar enough to this to suggest what an effective way to deal with this issue would be?

Luyren

  • *
  • Posts: 2754
https://luyren.itch.io/luyrens-miscellaneous-stencyl-behaviors

This resource pack has two saving behaviors that can be used for what you are trying to do. If you elaborate a bit on how you are using your created actors, I can guide you on how to best customize the behaviors. Mainly, if your created actors are tied to a scene or not.

If you don't want to use it, you can at least take a look at both Save Status and Save Actors behaviors if you want an idea of how to save actors.

My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

ceosol

  • *
  • Posts: 2279
You could also use lists. Make 5 lists (or however many you need) or a map. Each would be one specific item related to the characters. For instance, list one would be character name, list 2 is hair color, list 3 is clothes, list 4 is location, etc.

Galdon2004

  • *
  • Posts: 318
I can take a look at the behaviors, thanks.

As for elaboration, in the game you have a base that you are building, and characters may show up periodically to join it, and can be seen walking around the base. The characters would need to spawn actors for their clothes that stay on top of them to match their randomized appearances, and would need stats to track their coordinates on screen so the scene knows where to put them when reloading the scene and so the clothing actors know where to be, and probably stats for what the characters are good/bad at doing.

The reason normal global variables wouldn't work is that global variables have to be made in advance before the game runs, and I feel like I would need to dynamically create new variables and save them when a new character is added.

ceosol

  • *
  • Posts: 2279
That is what the list or map is for. You can add things and then save/load.

ceosol

  • *
  • Posts: 2279
This is a very quick example. You can draw it on the screen and keep running the program. The list keeps changing with every startup.

Galdon2004

  • *
  • Posts: 318
That line sounds like it would, add to a list the number of items in the list minus one, plus one?

Luyren

  • *
  • Posts: 2754
As for elaboration, in the game you have a base that you are building, and characters may show up periodically to join it, and can be seen walking around the base. The characters would need to spawn actors for their clothes that stay on top of them to match their randomized appearances, and would need stats to track their coordinates on screen so the scene knows where to put them when reloading the scene and so the clothing actors know where to be, and probably stats for what the characters are good/bad at doing.
If using my resource pack: Attach the "Save Status" behavior to the actors you want to save, and include all the values and attributes you want to save in the map. Also check the boolean "Scene Save."

On your scene, attach the behavior "Save Actors."

End result is: all the values you want will be saved, and when you return to that scene, your actors will be created at their last positions, and their values and attributes will be loaded.

Edit: for the clothing, you can check my RPG Elements pack, specifically the "Equipment" behavior. That handles creating actors based on the current equipment, and can be used for the clothing part if configured properly (and you'd just set their equipment when created by using the provided custom block). It also contains instructions on which values to save in order to work with the saving I described above.

Also
Quote
The reason normal global variables wouldn't work is that global variables have to be made in advance before the game runs, and I feel like I would need to dynamically create new variables and save them when a new character is added.
There are blocks to dynamically create both global variables and local variables.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

Galdon2004

  • *
  • Posts: 318
thanks I'll tinker with the behaviors. What blocks create global variables? I'm trying to find them now that you mention them, but I don't see it. The closest I can find is the set game attribute with name [] to [] block, but that doesn't create an attribute. if I put something into it that does not yet exist it just crashes the game in exe and is ignored in flash.

Luyren

  • *
  • Posts: 2754
The closest I can find is the set game attribute with name [] to [] block, but that doesn't create an attribute. if I put something into it that does not yet exist it just crashes the game in exe and is ignored in flash.
That is precisely the one. If it's crashing, I'd guess it's because you are trying to use it as a list or map without initializing it first.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

Galdon2004

  • *
  • Posts: 318
I assume you initiate by setting the variable's value before retrieving it?  Or is there another way to initialize the variable?

Luyren

  • *
  • Posts: 2754
All hidden lists and maps must be initialized by using the "create new list" and "create new map" blocks respectively. That's it.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

Galdon2004

  • *
  • Posts: 318
I see, the usage I was doing when the game would crash was when using text variables, not lists or maps.

Luyren

  • *
  • Posts: 2754
Post a screenshot of the code you tried.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

Galdon2004

  • *
  • Posts: 318
Here's a sample of some of the code from the other project, this one in particular refers to a number variable. If it is run with a typo in the variable name, or if I forget to pre-make variables with the character names before compiling, it crashes in the EXE version.