I wanna create a creature storage system for my game.
Basically i want it to work such that whenever I catch a new creature I want to save it’s data such as it’s health , name and level. Since it’s not limited to how many creatures the player catches , the storage would be infinite and hence i can’t use pre defined variables.
I tired using arrays to dynamically save the data but right now the issue that it happening is that even though the second slot data is saved in “slot2” instead of “slot1” it is still showing the data of slot2 whenever I wanna use slot1 data.
Pls help
this make it super easy to use. it also “create your storage” automatically every time an object is created (this is because object variables should be called instances variables. they are different for each instances.)
if you want to change the variable of a particular instance, simply pick that instance, and change it’s variable.
you just got the wrong approach. scene/global arrays are completely useless in your situation
Object variables only exist while the object exists and when created, the variables are set to the object variable’s default values.
Is this for a character selection mechanism. Like switchable characters?
If so, you have infinite options.
Option 1: Don’t delete the object. Hide it, disable any behavior(s) and possibly move it way off screen so it can’t collide with anything. Put all of the playable characters into a group and use that group object name for everything. Then before any other events check the object ID. Like ID of players equals currentID or currentSlot. That would pick just that object. Put all other events as a subevent.
Options 2 and 3: Same group concept but delete the objects when not needed. You wouldn’t need to check an object variable before things like collision. The difference between options 2 and 3 are where the variables are accessed.
Option 2: the variables are copied back and forth between a scene or global array or structure of structure variables before an object is deleted and after it is created.
Option 3: the variables are all kept in a scene or global array or structure of structures like slot[0].Data… You would pick the slot number by either checking another variable like slot[currentSlot].Data… or an object variable like slot[player.ID].Data… You could also use a structure of structures and use the character’s name instead of an index. slot[player.characterName].Data… or slot[player.ObjectName()].Data…
Option 4: Put all of the animations into 1 object and then change the animations to fit the character. This might get complicated if you have a ton of animations. The structure or array of structures would be in the object.
Option 5: create the character as a custom (prefab) object. The events would be similar but it would move some of the events to the custom control. The custom control could contain the objects and the variables in a structure or array. Same techniques but it would streamline the main event sheet bc the scene would just use the custom object.
It is a full creature collecting and battling game , you can catch an infinite amount of creatures and when battling you can switch to any creatures that you have caught
The first method seems like the simplest and best to me but one thing I’m worried about though is that wouldn’t it cause lag in the game if all of the objects are just existing in the scene at all times ? Especially when the player has a lot of creatures caught or would it just be fine
And also how would the objects even transfer when I switch to a different scene
If there are a very large number than maybe it’s best to add and delete them and store their data in a global variable and/or stage especially if there are multi scenes. Global variables are the only thing that retains information between scenes other than storage or some other external method.
This is probably one of the easier approachs. This keeps the variables in a global array variable. The object only needs a single variable. In my example it’s ID. It then uses that number to reference the variables.
I added the location of 10 objects to the array. I used a slider control to decide which object to add or delete. I used a save and load button and a text object as the character.
(I guess I didn’t need the change position. The object can be created directly from the array. That’s a leftover from a previous version)
My original concept copied the variables back and forth using json.
You can only create variables that aren’t already defined if they are in a structure. Structures can use both defined and undefined. But using different structure setups can be difficult.
Do you know why this isn’t working ? Even though in the second event I’ve made it so Data[slot2] gets changed but the issue I’m facing is that even though slot2 values is getting updated , whenever I wanna use slot1 values it’s still returning slot2 idk why this is happening
I don’t see any issues with the events. Does the array look correct in the debugger? Could it be the way the variable is read?
Using separate events for each slot is going to add a lot of events to maintain and debug. You can build the slot name by adding a variable to the slot name.
I can’t use debugger , it’s a premium feature
And about reading the array wrong , this is the event where I’m trynna use it but it’s creating slot2 object whenever I catch the second creature instead of always the first
Unless you are using the mobile app (which is designed for/made possible by subscriptions) The debugger is not a premium feature. It does pop up with text asking you to subscribe, but has a large continue anyway button.