Skip to main content
added 196 characters in body
Source Link
Theraot
  • 28.2k
  • 4
  • 55
  • 83

Let us talk about inventories.

Real world inventories.

An object in a store have a unique id (e.g. a Serial Number) and a model (e.g. "Rusted Sword 2000").

And there might be other information attached to it, for example a manufacturer/provider (e.g. "Acme Inc."). Now, is that attached to the unique id or the model?

Well, all objects of the same model are by the same manufacturer ("Acme Inc"Inc." makes "Rusted Sword 2000"), so it does not make sense to attach that to the unique id, but to the model.

Other attributes might be different per item. For example if you need to track where it is in the store, or if it is damaged, and so on. That information need to be attached to the unique id.


Now, in your game, you have rusted sword object. Does that object represent the unique item, or does it represent the model? Well, you might need both.

You will have an object that represents the item, which have information about it such as the durability, or upgrades that the player has added to it.

And that object must have a reference to anotehranother object that represents the model, which will have information common to all items of the same kind, for example its base stats.


Now, as you can imagine, if you put the upgrades in the object that represents the model, then it will apply to all items. Which seems to be the issue at hand. And you would solve it by moving that information to the object that represents the unique item.

It might be the case that you do not have an object to represent the unique item, in which case you need to come up with it.

In any case, I believe you need to think about the structure of your data. And this is not a problem of how you store or load it.

Addendum: I've been saying object, but these might be rows in a table, or items in an array, whatever works.

Let us talk about inventories.

Real world inventories.

An object in a store have a unique id (e.g. a Serial Number) and a model (e.g. "Rusted Sword 2000").

And there might be other information attached to it, for example a manufacturer/provider (e.g. "Acme Inc."). Now, is that attached to the unique id or the model?

Well, all objects of the same model are by the same manufacturer ("Acme Inc" makes "Rusted Sword 2000"), so it does not make sense to attach that to the unique id, but to the model.


Now, in your game, you have rusted sword object. Does that object represent the unique item, or does it represent the model? Well, you might need both.

You will have an object that represents the item, which have information about it such as the durability, or upgrades that the player has added to it.

And that object must have a reference to anotehr object that represents the model, which will have information common to all items of the same kind, for example its base stats.


Now, as you can imagine, if you put the upgrades in the object that represents the model, then it will apply to all items. Which seems to be the issue at hand. And you would solve it by moving that information to the object that represents the unique item.

It might be the case that you do not have an object to represent the unique item, in which case you need to come up with it.

In any case, I believe you need to think about the structure of your data. And this is not a problem of how you store or load it.

Addendum: I've been saying object, but these might be rows in a table, or items in an array, whatever works.

Let us talk about inventories.

Real world inventories.

An object in a store have a unique id (e.g. a Serial Number) and a model (e.g. "Rusted Sword 2000").

And there might be other information attached to it, for example a manufacturer/provider (e.g. "Acme Inc."). Now, is that attached to the unique id or the model?

Well, all objects of the same model are by the same manufacturer ("Acme Inc." makes "Rusted Sword 2000"), so it does not make sense to attach that to the unique id, but to the model.

Other attributes might be different per item. For example if you need to track where it is in the store, or if it is damaged, and so on. That information need to be attached to the unique id.


Now, in your game, you have rusted sword object. Does that object represent the unique item, or does it represent the model? Well, you might need both.

You will have an object that represents the item, which have information about it such as the durability, or upgrades that the player has added to it.

And that object must have a reference to another object that represents the model, which will have information common to all items of the same kind, for example its base stats.


Now, as you can imagine, if you put the upgrades in the object that represents the model, then it will apply to all items. Which seems to be the issue at hand. And you would solve it by moving that information to the object that represents the unique item.

It might be the case that you do not have an object to represent the unique item, in which case you need to come up with it.

In any case, I believe you need to think about the structure of your data. And this is not a problem of how you store or load it.

Addendum: I've been saying object, but these might be rows in a table, or items in an array, whatever works.

Source Link
Theraot
  • 28.2k
  • 4
  • 55
  • 83

Let us talk about inventories.

Real world inventories.

An object in a store have a unique id (e.g. a Serial Number) and a model (e.g. "Rusted Sword 2000").

And there might be other information attached to it, for example a manufacturer/provider (e.g. "Acme Inc."). Now, is that attached to the unique id or the model?

Well, all objects of the same model are by the same manufacturer ("Acme Inc" makes "Rusted Sword 2000"), so it does not make sense to attach that to the unique id, but to the model.


Now, in your game, you have rusted sword object. Does that object represent the unique item, or does it represent the model? Well, you might need both.

You will have an object that represents the item, which have information about it such as the durability, or upgrades that the player has added to it.

And that object must have a reference to anotehr object that represents the model, which will have information common to all items of the same kind, for example its base stats.


Now, as you can imagine, if you put the upgrades in the object that represents the model, then it will apply to all items. Which seems to be the issue at hand. And you would solve it by moving that information to the object that represents the unique item.

It might be the case that you do not have an object to represent the unique item, in which case you need to come up with it.

In any case, I believe you need to think about the structure of your data. And this is not a problem of how you store or load it.

Addendum: I've been saying object, but these might be rows in a table, or items in an array, whatever works.