Hey,

I am trying to think of a way to store a characters inventory in an RPG style game. I wasn't sure how it's normally done, but what I could think of so far was the following:

Items have a unique ID number. This ID number corresponds to their position in a list.

Ex. a one-hand sword ID#4.

LDAMAG(4) would be the swords damage.
LCOSTS(4) would be the swords cost.
etc.

Issue being the name, since it seems I would need to store the alphabetical numeric in a list. This would mean you don't know the length of the name. I suppose you could have a name maximum, let's say 20 characters. So you would do ID#4 is position 80-100 in LNAMES. So you pull those 20, and drop the empty positions.

So, when the user goes to their inventory, you would loop through a list with their item IDs they own, and then pull the data from individual lists based on the ID to display and allow them to use.

Is there a much easier way to go about this?
Rmontgomery07 wrote:

Items have a unique ID number. This ID number corresponds to their position in a list.

Ex. a one-hand sword ID#4.

LDAMAG(4) would be the swords damage.
LCOSTS(4) would be the swords cost.
etc.


I would suggest you try to compress information about the item into a single list entry to save on memory (and a bit of time). As a rather simple example, you could store the damage as the integer part of a number, and the cost as a decimal, and store the entire number in the list. So,


Code:
:ʟITEMS(4→X
:iPart(X     \\Damage
:10fPart(X     \\Cost


If the cost is more than 1 digit (greater than 9), then replace 10fPart( with 100fPart( or larger (10 to the power of however many digits). A more robust guide on general compression techniques can be found here. You are able to store up to 14 digits in a single list entry (28 if you make it a complex list), so take advantage of the space that you have.
Rmontgomery07 wrote:
Hey,

I am trying to think of a way to store a characters inventory in an RPG style game. I wasn't sure how it's normally done, but what I could think of so far was the following:

Items have a unique ID number. This ID number corresponds to their position in a list.

Ex. a one-hand sword ID#4.

LDAMAG(4) would be the swords damage.
LCOSTS(4) would be the swords cost.
etc.

Issue being the name, since it seems I would need to store the alphabetical numeric in a list. This would mean you don't know the length of the name. I suppose you could have a name maximum, let's say 20 characters. So you would do ID#4 is position 80-100 in LNAMES. So you pull those 20, and drop the empty positions.

So, when the user goes to their inventory, you would loop through a list with their item IDs they own, and then pull the data from individual lists based on the ID to display and allow them to use.

Is there a much easier way to go about this?


Use a integer in place for the name to indicate its position in a list of strings which you can define using a string and a different list
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement