Text Adventure Begun (well nearley)

Blitz3D Forums/Blitz3D Beginners Area/Text Adventure Begun (well nearley)

Infantry_Nutter(Posted 2004) [#1]
Ok, I have a story i Have drawings on paper of rooms etc I have a list of all the objects in the game, but Ive come across a problem I need a Way of checking on what the Player is carrying and if the Player Can use that object with somthing in a Certain room,

Example "small key with small lock in green room"

I thought I could use arrays? or maybe true/false statements?

Also is it wrong to use a differnt function for each room?

Examople
Function room1()
function room2()

etc


jhocking(Posted 2004) [#2]
Arrays would work but could be clumsy. I would use types.

As for the rooms, it is probably overkill to use a different function for each room. Since the rooms will be pretty identical in terms of what the player can do in them, you only need one room function which, among other things, displays the description for the current room. Store descriptions for all the rooms in an array or with types and have the function reference the appropriate description. Then, whenever the player moves, have the room function switch which room it is referencing.


Infantry_Nutter(Posted 2004) [#3]
Thanks Maybe I can start getting some coding tonight :), I may try both ways, first with types then with arrays and see which is best.

One last thing, when usoing arrays do I have to keep a Restore loop running for when it checks for Inventory and possible routes?


soja(Posted 2004) [#4]
Here's how I might set it up:
Type Room
  Field ID%, Name$, Desc$
  Field North.Room, South.Room, East.Room, West.Room
  Field Item[MAX_ITEMS_IN_ROOM] ; Can contain a certain number of items
End Type

Type Player
  Field Name%, Strength%, Intelligence%
  Field Inventory.Item[NUM_ITEMS_IN_GAME]
End Type

Type Item
  Field ID% ; To be indexed on Player\Inventory
  Field Name$, Desc$
  Field Location.Room
  Field UsedWith.Item[3] ; Can be used with a few other items
End Type


Now to check if a certain item can be used with another, you might do something like this:
ItemUsed.Item = Player\Inventory[ItemID]
ItemUsedOn.Item = Room\Item[2]
If ItemUsed\UsedWith[1] = ItemUsedOn Then Print "Yes, this item can be used with that item."

This is just to give you some ideas. It might not be the best way.


_PJ_(Posted 2004) [#5]
I remember from the old speccy days, some Basic-language text-adventures were written using a code sequence for each room.

i.e '1A.E71.N5.S2.O50.O31'

Where this would be interpreted as

LOCATION: 1A
EXIT EAST TO: 71
EXIT NORTH TO: 5
EXIT SOUTH TO: 2
OBJECT IN ROOM: 50 and 31

or similar!


Infantry_Nutter(Posted 2004) [#6]
Hmmmm Well Im going to *Punch* whoever said that writing a text advnture was a good first easy program, all this stuff keeps me awake at night tying to figure it out, I solve one problem and I am then presented with another :)

But the real problem is I refuse to Start a Differnt game its become an obsession Im doomed! But watch this space I may just finish it!.


jhocking(Posted 2004) [#7]
Relative to other games a text adventure IS easy. The key word is "relative." Writing a text adventure isn't easy relative to, say, programming a loop to count from 1 to 1000, but relative to writing some other game it is easy. That is, writing something else would be even harder.


Infantry_Nutter(Posted 2004) [#8]
Hmmmm well my futre in programming doesent look good then :)


_PJ_(Posted 2004) [#9]
Good luck! Persistence and patience is a good quality for a programmer :)

----

Still, by encountering all the problems, and their solutions, its a way of learning, right?


WolRon(Posted 2004) [#10]
Trust me when I say, "When you are finished programming this game, the next (what should be) harder one will be MUCH easier."


jhocking(Posted 2004) [#11]
Yeah, that's a very important point. The best advice I got when I first started programming games is to start with the easiest project I can think of (I did Minesweeper) and gradually ramp up the difficulty with each project I undertake. Most people try to write a MMORPG right out of the gate, but the experience and confidence (the latter is definitely overlooked a lot) you gain from starting on easier projects will make things much easier for you on harder projects. Anyone can start a game but only a rare few can finish one, and that finishing ability is only gained from having completed games in the past. And if you've never programmed a game before you are MUCH more likely to complete something easy than something hard.

My recommendation if you are finding this project too difficult is make it easier. Cut down the number of items and rooms in your game until it is something you can easily finish. Then finish it, and start a new project which is a bit harder. Above all else, do NOT switch to a new project until this one is done. There are of course legitamite reasons for abandoning a project to work on something else, but when you are just starting out you want to build up the habit of finishing what you start.

In fact, a logical small increase in difficulty for your next project would be adding some graphics. Complete this project without graphics, and then do Space Invaders for your next project.


puki(Posted 2004) [#12]
"Infantry_Nutter" - your original question is easy to do.

All objects will have a location value (of where they are held). Suppose your game has 500 or so locations. Set up the player's inventory to be 600 (for example) and all non-player characters to have successesive numbers.

When legally taking a object, change it's location value to 600 (or whatever). When you do a inventory check - you search through the entire list of objects and display all those where the object location is equal to 600 (or whatever) - when dropping an object change the object location to the location number. Also, you can make other objects have inventories in the same way - such as a backpacks or chests - whatever you like. Backpack 1 could have location number 700 - the sky is the limit.

Actually, what you are doing is fairly easy - it's just you haven't yet made the connections - you will.

Note:
You don't need to use restore for this.

I wouldn't store location descriptions in arrays - keep that stuff as data.


Gauge(Posted 2004) [#13]
Heres a few of my types for my mud project:

Type player
Field stream
Field status
Field Id
Field name$
Field password$
Field curr_room
Field curr_area
Field title$
Field desc$[50]
Field pclass
Field prace
Field sex
Field comm
Field comm1$
Field comm2$
Field comm3$
Field comm4$
Field msg$
Field experience#
Field exptnl#
Field stance
Field postion
Field vision
Field pinv.inv[100]
Field EqWorn[21]
Field paff.affects[100]
Field Enc
Field Curr_Str
Field Curr_Dex
Field Curr_Int
Field Curr_Wis
Field Curr_Con
Field Base_Str
Field Base_Dex
Field Base_Int
Field Base_Wis
Field Base_Con
Field Pcolor
Field gold
Field silver
Field bank
Field pskills.pskills[100]
Field pspells.pspells[100]
End Type

Type Inventory
Field InvType
Field InvId
Field ItemName$
Field ItemNumber
Field Weight
Field desc1$
Field desc2$
Field Alighnment
Field IAcValue
Field Imres
Field ItemLevel
Field ItemCost
Field Damage
Field itd.DamageNoun[3]
Field Material
End Type

Type Race
Field racename$
Field RaceNumber
Field Base_Str
Field Base_Dex
Field Base_Con
Field Base_Int
Field Base_Wis
Field rskills.rskills[100]
field rspells.rspells[100]
Field Rvision
Field ExpMult
End Type

Type Area
Field Areaname$
Field AreaNumber
Field ar.room[100]
Field weather
End Type

Type Room
Field Roomname$
Field RoomNumber
Field ralso.Alsohere[100]
Field rlying.Lyinghere[100]
Field Light
Field MvCost
Field RoomType
End Type

Type Class
Field Classname$
Field ClassNumber
Field cskills.cskills
Field cspells.cspells
field plus_Str
Field Plus_Dex
Field Plus_Con
Field Plus_Int
Field Plus_Wis
Field Vision
Field ExpCost
Field MaxArmor
Field Cweapons
End Type



The room/area/class/race number, and player Id is because I'm doing arrays in types. I'm dimming player by 1,000 for now, and then reorganizing them when someone quits, eventually i may change it so that there can be unlimited players but it'll have to store each player in a temporary field, besides you can set dim p.player(1000000) if you have the memory, etc. I also have to clean it up and make it look better, and comm,comm1$,etc is going to be changed to pc.command_buffer(cbuff for short) so that it'll store up to ten commands, but anyways, thats my list. Good luck, and lemme know if you want some code.


Warren(Posted 2004) [#14]
jhocking

Excellent advice there. That's all exactly what I wish I had known earlier. I've been trying to write games for years and only in the last few have I buckled down and gotten serious. Bubble Bomb was a good first step and a pretty simple game. SETH's Puzzle Boxes is a level above that and the next game will go higher still.

Start off crawling and slowly build to a run. That's the way to ensure success...


jhocking(Posted 2004) [#15]
Somewhat ironic to hear you say that since you work for Epic, but then I suppose your work there is always about contributing a small part to a large project, not finishing a project of your own. It just goes to show, skill at programming and being able to finish a project are very different things, and having a lot of the former does not automatically translate into the latter.


Warren(Posted 2004) [#16]
Precisely. I don't have the shoulder the projects at Epic, only my portion of them. It's a world of difference from writing an entire game by yourself...