Question about pet system for simulator

I’m currently working on a simulator and wondering whether it’s better to rely on pet names or assign unique IDs to every pet, for example: Name: Dog; Id: 57812758. Also, should I create two separate modules - one for PetData and one for EggData? Basically, PetData would include stats for each pet, and EggData would contain information about which pets are inside each egg along with their drop chances. Then, I could require PetData inside EggData to reference pet names.

1 Like

I would probably keep it simple with names as it’s easier to understand and there probably wont be any pets with the same name. I would also have 2 seperate modules just to keep it simple

Representing instances of “Pets”, for example in a player’s inventory or their equipped pets, the use of unique IDs is ultimately a code design choice. There are times where the use of unique IDs can make programming easier, however it is not necessarily required. In my opinion, you should only use unique IDs if each instance of a pet is truly unique (in other words, every instance of a “Cat” is distinct from every other instance of a “Cat”).

As far PetData and EggData, I would definitely recommend separating the representation of these information modules as they are each essentially libraries with different responsibilities. For example, you might setup a PetData library (as a ModuleScript or hierarchy of ModuleScripts) to contain the information relevant to each pet type:

local PetData = {}

PetData.Cat = {
   Attack = 1,
   Speed = 1
}

PetData.Dot = {
   Attack = 2,
   Speed = 2
}

return PetData 

However, the responsibility of the EggData library is to represent the eggs and the chance that a certain pet can hatch from each egg type:

local EggData = {}

EggData.GrassEgg = { --For each "EggType" table, the keys should correspond to a key in the PetData library.
   Cat = 4, --The values within this table represent the "weight" of this entry being chosen
   Dog = 2
}

return EggData
1 Like

Yeah, but I think if something happens you could easily replace Pet Name using id’s without need to change something in player data store.

Are you talking about the name of the class, or the name as in like a nickname that a player gives that pet? If you’re talking about the class, that’s more of a problem that your data loading system would have to tackle by upgrading old data to a new format. If you’re talking about nicknames, then that would be one case pointing towards each pet being its own unique instance and may influence whether or not you want to use unique IDs (although they’re still not explicitly required from that alone).

Well, I mean, I think it would be easier to make changes to pets by assigning a unique ID to each pet type - like Dog (1), Cat (2), and so on. It would also make it easier to save player pets using just the IDs, so you wouldn’t have to worry about the data store.