Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Text Adventure Inventory

Author
Message
Lilwereboy
14
Years of Service
User Offline
Joined: 21st Dec 2009
Location:
Posted: 8th Aug 2011 13:50
Ummmm... I was wondering if there was some kind of way to add an inventory system to the text adventure game im making. Some along the lines of:

If pistol=1 print "You have a pistol"


And some kind of way to make it useable, Im outta ideas :/

Shhhhhhh..... I'm eatin a cheeeeZzzburger
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 8th Aug 2011 16:08
At a very simple level, you want an array of items available:



Then your player needs an array of what he owns:



Lilwereboy
14
Years of Service
User Offline
Joined: 21st Dec 2009
Location:
Posted: 9th Aug 2011 10:39
Thanks for that, but one more thing, how do i make it check if the item is in the inventory when the player calls for it?

For example:

You are getting attacked.
Use knife
You don't have a knife
Pick up knife
Got it!
Use knife
You win the battle!


Something along those lines

Shhhhhhh..... I'm eatin a cheeeeZzzburger
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 9th Aug 2011 18:32
It's easier for text adventures to just have one item array rather than one for the rooms and one for the player. The items location can both be used to track what room number the item is (locations = 1 to 999) and if the item is actually being held by the player (location = 1000). A location of zero is an item that no longer exists.

Data structure:


Data:


When you check for inventory all you need is a FOR/NEXT loop to look at the item array and look at each item with a location of 1000 (or whatever number you choose for the players inventory).

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 10th Aug 2011 01:30
The DBP challenge thread had a text adventure challenge some time ago, I bet there'd be some good ideas floating around there.

Login to post a reply

Server time is: 2024-11-22 19:06:01
Your offset time is: 2024-11-22 19:06:01