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.

DarkBASIC Discussion / ignoring parts of an input???

Author
Message
Hell Forged Angel
23
Years of Service
User Offline
Joined: 3rd Jan 2003
Location: United Kingdom
Posted: 15th Apr 2003 20:15
i want to make a text game that involves typing commands but the commands would have date eg:

to look at the vase ont the table the player would type sumthing like
look:vase
is there any way i could test the input for the first pat (look) and the second part (vase) seprately?

otherwise i would have to make a look command for every object in the room.
Darkness will claim us all
Hell IVIonkey
23
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 15th Apr 2003 21:26
if left$(string$, 4)="look" then string$=right$(string$, len(string$)-4)

I didn't test it, but it should work.
ReD_eYe
23
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 15th Apr 2003 22:13
yeah look at the text commands they can make things easier

'You were born crying while people around you smiled'
Hell IVIonkey
23
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 16th Apr 2003 01:19
err, that should read "...len(string$)-5)" in order to remove the colon. However, you may want to create some sort of loop to test for extra spaces between words, as most games of this sort do.
Hell Forged Angel
23
Years of Service
User Offline
Joined: 3rd Jan 2003
Location: United Kingdom
Posted: 16th Apr 2003 17:21
ok thnks for the help ill try that out x-d

Darkness will claim us all
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 16th Apr 2003 20:12
Do a web search for "Parsing". Most text based games are based on a Parsing engine. This deciphers the users command, strips out the rubbish and converts it to variables that you can use in your program to control program flow.

Thanks in advance.
All the Best,
StevieVee
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 16th Apr 2003 23:38
"...len(string$)-5)"
that would only work if you knew the length of the command expected.

look:vase

search the string for a colon. to the left of the colon is your command. to the right of the colon would be the object's name or whatever you want it to be.

Hell IVIonkey
23
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 17th Apr 2003 01:13
I don't know what you're on about , but try it yourself:
The Darthster
23
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 17th Apr 2003 01:41 Edited at: 17th Apr 2003 01:45
This is how I did it, back in QB. I checked for a space " ", then knew that one word was the verb, and the other was the object.

for i=0 to len(string$)
if mid$(string$,i,1)=" " then verb$=left$(string$,i):object$=right$(string$,len(string$)-i-1):break
next i

This'd give a verb$ and an object$. Then, you just loop through your array of stuff, and see if they match. Notice I'm using 3 types of variable; verb is an integer that holds the index of the verb, verb$ is the verb that the user typed in, and verbs$ is the array of verbs. Similarly for objects, except objpos() is an array showing where the object is.

dim verbs$(3)
data "look"
data "take"
data "drop"

dim objects$(2)
data "vase"
data "brick"

dim objpos(2)

rem Not bothering to read the data, to save typing.

for i=0 to 2
if verb$=verbs$(i) then verb=i
next i

for i=0 to 1
if object$=objects$(i) then object=i
next i

select case verb

case is = 0
rem Look
select case object
case is = 0
message$="It's a vase, very nice it is too."
end case
case is = 1
message$="It's a brick. You could lob it through a window."
end case
end select
if message$="" then message$="You don't see that here"
end case

case is = 1
rem Take
if object >= 0 and object <= 1 and objpos(object)=location
objpos(object)=-1
message$="Taken"
else
message$="You can't take that!"
endif
end case

case is = 2
rem Drop
if object >= 0 and object <= 1 and objpos(object)=-1
objpos(object)=location
message$="Dropped"
else
message$="You can't drop that!"
endif
end case

end select

If message$="" then message$="You make no sense."

Sorry about the code, it's a hybrid of DB, QB, VB and randomness that occurs in my head, and my formatting didn't work out properly. You should be able to work out what is happening though.

Once I was but the learner,
now, I am the Master.
Obear
23
Years of Service
User Offline
Joined: 13th Oct 2002
Location:
Posted: 17th Apr 2003 01:48 Edited at: 17th Apr 2003 01:49
darn TheDarthster whats that language? Dark Quick Visual Basic? lol

Hell Forged Angel
23
Years of Service
User Offline
Joined: 3rd Jan 2003
Location: United Kingdom
Posted: 21st Apr 2003 20:12
wow thanks for the help hopefully i will be able to find out all i need to start making the game soon ...... anygood story writers out there???

Darkness will claim us all

Login to post a reply

Server time is: 2026-06-11 21:22:02
Your offset time is: 2026-06-11 21:22:02