8 Replies - 624 Views - Last Post: 21 March 2011 - 12:12 PM Rate Topic: -----

#1 tpgames  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 24-February 11

inventory: player moves items between drawers, etc.?

Posted 21 March 2011 - 10:23 AM

I'm having a hard time figuring out what code to use. What I want to accomplish is a inventory system (trolley) where the player can organize any item into any drawer or bookshelf or dorm and put it in any order they feel like it.

I have been reading about dict, lists, datat, LaTeX, etc. However, I still do not really know where to begin, as nothing I've read so far tells me which system of code I should use that would allow the player to rearrange as many times as they want to, and in any order they want to.

I assumed LaTeX won't work. I'm not printing this. This is dictionary/ lists.

This isn't a MMORPG, I don't have to worry about players. The one player will have 1 trolley. Trolley is its cart.
Thanks!

# these are the 3 main areas of storage.
trolleyinv = Datat(["trolleydrawers", "trolleydorm", "trolleybkv"])

# trolleydrawers: 6 rows, each row contains 1 drawer that when opened, reveals a drawer with 2 slots |[][]|
# trolleydorm: anything plopped into this bin would be organized between rooms using a different page.
# trolleybkv = bookshelves: There are 4 bookshelves that pull out to reveal 6 shelves per bookshelf. 
# |_||_||_||_|
# |_||_||_||_|
# |_||_||_||_|
# |_||_||_||_|
# |_||_||_||_|
# |_||_||_||_|
# 
# The drawers
#  |[][]|
#  |[][]|
#  |[][]|
#  |[][]|
#  |[][]|
#  |[][]|





More Info:
Each bookshelf can hold an unlimited number of books lengthwise.
Each drawer can hold any number of items widthwise and depthwise. Thus, I could put items 10 across and 20 deep if I wanted to.

However, how would I program this? Which method would net me what I wanted? Dicts? Lists? Datat's module? And what should I keep in mind?

Thanks!

This post has been edited by tpgames: 21 March 2011 - 10:52 AM


Is This A Good Question/Topic? 0
  • +

Replies To: inventory: player moves items between drawers, etc.?

#2 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: inventory: player moves items between drawers, etc.?

Posted 21 March 2011 - 10:27 AM

I'm not entirely familiar with datat, but everything you mentioned is doable using lists. I would not recommend using a dictionary.
Was This Post Helpful? 0
  • +
  • -

#3 tpgames  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 24-February 11

Re: inventory: player moves items between drawers, etc.?

Posted 21 March 2011 - 11:00 AM

With lists, would I use nested lists? Would I store the info in at db file or what?

And, how would I deal with accessing a specific item? would each item have its own variable name?

if player wanted books on cats, and the books were arranged in the order
|ants|dogs|bats|cats|

cats would be the number 3 in python.
but if player moved the books thus:
|dogs|ants|cats|bats|

then cats moves to number 2 in python.
How would I deal with this so that when player mouses on "cats book" they get cats book? With nested lists, I can see where I could get an error if a player moves half the books to the 2nd shelf from the 1st shelf. How would I use len to fix this?

Thanks!

This post has been edited by tpgames: 21 March 2011 - 11:10 AM

Was This Post Helpful? 0
  • +
  • -

#4 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: inventory: player moves items between drawers, etc.?

Posted 21 March 2011 - 11:11 AM

Well, these are design decisions that you'd need to implement.

With nested lists, 4 slots per bookshelf could look something like this:
bookCase=[
["","","",""],
["","","",""],
["","","",""],
["","","",""],
["","","",""],
["","","",""]
]


How would you store it?
That's your decision to be honest. For something like this, perhaps you should consider Pickling

Quote

How would I deal with this so that when player mouses on "cats book" they get cats book?

Well, option A is to simply search the book shelf and find the book on cats, option B is for each book to have a value associated with it giving you it's location, option C is having a separate data structure that holds the locations of books... if you want to do that, Dictionaries may end up being better after all.

Could you please expand a little on your "master plan" for this project? What will the finished application look like? Will it be command line or graphical? Do you want the system to search a book shelf or will it always have access to every book?

This post has been edited by atraub: 21 March 2011 - 11:13 AM

Was This Post Helpful? 1
  • +
  • -

#5 tpgames  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 24-February 11

Re: inventory: player moves items between drawers, etc.?

Posted 21 March 2011 - 11:24 AM

View Postatraub, on 21 March 2011 - 11:11 AM, said:

Well, these are design decisions that you'd need to implement.

With nested lists, 4 slots per bookshelf could look something like this:
bookCase=[
["","","",""],
["","","",""],
["","","",""],
["","","",""],
["","","",""],
["","","",""]
]


How would you store it?
That's your decision to be honest. For something like this, perhaps you should consider Pickling

Quote

How would I deal with this so that when player mouses on "cats book" they get cats book?

Well, option A is to simply search the book shelf and find the book on cats, option B is for each book to have a value associated with it giving you it's location, option C is having a separate data structure that holds the locations of books... if you want to do that, Dictionaries may end up being better after all.

Could you please expand a little on your "master plan" for this project? What will the finished application look like? Will it be command line or graphical? Do you want the system to search a book shelf or will it always have access to every book?


Ultimately I want to have:
1) Player be able to rearrange any item and put it anywheres
2) Player be able to choose item and use it.
3) If player chooses workbook, then this will bring up part of game where book can be "written" in, and a game played where player answer questions, inputs answers (may be crossword puzzle, etc.)
4) If player chooses Alchemy Items, can use those items when performing a lab experiment.
5) The player would see a graphical representation, where each item will be a set width and height in storage (for ease of programming).
6) The game will always have access to every item, every book.
7) Player can buy more books, more items without limit from various stores. But, can only use 1 trolley at a time for now (to make the inventory simpler to code).

As far as storing the data and all the 'decisions' I need to make, my only requirements is that its the easiest to program given what I'm trying to accomplish, and does what I want it to do. Beyond that, I'm not picky. lol

I wasn't sure on how that graphical representation would be represented in lists, but I'm now remembering the all important URL to the png file. LOL
Thanks for all your help!
Was This Post Helpful? 0
  • +
  • -

#6 tpgames  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 24-February 11

Re: inventory: player moves items between drawers, etc.?

Posted 21 March 2011 - 11:33 AM

My brain can handle each item having its own variable name. That makes sense to me.

The bookshelves are of infinite length so that the player can put any number of books on any shelf. I wouldn't have 'wrapping' to next shelf this way. I'm not sure what else to tell you. I think I've covered everything. I am using python 2.6 and am rereading the docs on lists and data structures.
Thanks!
Was This Post Helpful? 0
  • +
  • -

#7 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: inventory: player moves items between drawers, etc.?

Posted 21 March 2011 - 11:38 AM

With a point and click scenario, coordinates on the screen could correspond to slots in the nested list.
Was This Post Helpful? 1
  • +
  • -

#8 tpgames  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 24-February 11

Re: inventory: player moves items between drawers, etc.?

Posted 21 March 2011 - 11:54 AM

View Postatraub, on 21 March 2011 - 11:38 AM, said:

With a point and click scenario, coordinates on the screen could correspond to slots in the nested list.


Okay, so I'd have hotspots/tuples then. Sweet! That is easier then using len. lol

As I looked at how many books a player would most likely have, I'm finding that I could actually limit the number of books one could put on a shelf and that might actually make the coding simpler if I were to have a set number of slots across and down. In my case, 6 slots across and 6 shelves down giving me 36 books per shelving unit.

#Lists with Nested Lists if necessary
#inv = inventory
#bkv = bookshelves


trolleyinv = ["trolleydrawers", "trolleydorm", "trolleybkv"]
trolleybkv1a = ["Spells 1", "Spells Workbook 1", "Literary 1", "Writing 1", \
                   "Alchemy 1", "Alchemy Workbook 1"]
                   
trolleybkv1b = ["Greek 1", "Greek Workbook 1", "Herbs and Plants 1", "General Majics 1", "", ""]

trolleybkv1c = ["Computer Programming 1", "Computer Programming Workbook 1", "", "", "", ""]

trolleybkv1d = ["Animagery", "Telepathy", "Telekinesis", "", "", ""]
trolleybkv1e = ["telekinesis", "Divinus", "Dark vs. Light", "", "", ""]
trolleybkv1f = ["Artistry", "Latin 1", "Latin Workbook 1", "", "", ""]

trolleybkv2a = ["Numberology 1", "Numberology Workbook 1", "Hebrew 1", "Hebrew Workbook 1", "", ""]
trolleybkv2b = ["German 1", "German Workbook 1", "Animal Language 1", Animal Language Workbook 1", "", ""]
trolleybkv2c = ["", "", "", "", "", ""]
trolleybkv2d = ["", "", "", "", "", ""]
trolleybkv2e = ["", "", "", "", "", ""]
trolleybkv2f = ["", "", "", "", "", ""]

etc.


Was This Post Helpful? 0
  • +
  • -

#9 tpgames  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 24-February 11

Re: inventory: player moves items between drawers, etc.?

Posted 21 March 2011 - 12:12 PM

Thus with the tuples, I'd have:
# tuples/hotspots
# 6 books across, all with the w x h of 100 x 100 = 600 acroos and 600 down.

# bkv1 = bookshelve one 1a - 1f = slots on 1st shelf
bkv1slot1a = (0, 100, 100, 100)
bkv1slot1b = (100, 200, 100, 100)
bkv1slot1c = (200, 300, 100, 100)
bkv1slot1d = (300, 400, 100, 100)
bkv1slot1e = (400, 500, 100, 100)
bkv1slot1f = (500, 600, 100, 100)

# slots on 2nd shelf for bookshelf 1
bkv1slot2a = (0, 100, 100, 100)
bkv1slot2b = (100, 200, 100, 100)
bkv1slot2c = (200, 300, 100, 100)
bkv1slot2d = (300, 400, 100, 100)
bkv1slot2e = (400, 500, 100, 100)
bkv1slot2f = (500, 600, 100, 100)

etc. 



When I figure out more of the code (the bits not identical to the above patterns), I'll post it here to see where I might have gone wrong. And, I'll attempt to get both posted codes working together. (This might take me a couple days or longer.)
Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1