1. Procedures and Parameters

All,

   I have brought this up before on this list, but do not
recall the answers.  I have a procedure called Look() in my
program that is executed if the user inputs the word look,
but I also want to use the same routine if the user enters
look vase, the problem I am facing is how to handle the user
input.  If the user enters just look, it should print something
like "You are standing in the dining room, there are exits to
the North and West." or something to that effect, but if the
user enters look vase, it should print something like
"The vase is an antique, and worth a lot of money, it is blue
with red flowers on it".

The problem here is this, if define the Look procedure in the
following manner to handle input such as look

global procedure Look()
    ..........
    puts(You look.......
end procedure

and the user enters   look vase   then the program aborts
with the following message:

Syntax error - expected to see possibly ')', not a variable

If I define the Look procedure in the following manner
to handle input such as     look vase

global procedure Look( sequence Obj)
    ...........
    puts(You look........
end procedure

and the user enters   look   then presses return the
program aborts with the following message:

Look() needs 1 arguments, not 0

These are interpreter error messages, all I could come
up with was to define the procedure the latter way and
if the user only enters look, to pass the procedure a
DUMMY parameter, such as Look(DummyPar).

Is there a better more efficient way to handle this?

Thanks In Advance,

--
+ + +  Rev. Ferlin Scarborough  -  Centreville, Alabama  -  USA

          http://sites.netscape.net/fscarborough/homepage

MailTo:ferlin at sandw.net
MailTo:ferlin at email.com
MailTo:fscarborough at netscape.net

new topic     » topic index » view message » categorize

2. Re: Procedures and Parameters

Hello Ferlin,

procedure Look (object thing)
  puts (1, "blah blah")
end procedure

if equal (input_string, "look") then
  Look (0)
elsif equal (input_string[1..5], "look ") then
  Look (input_string [6..length (input_string)])
end if

how's this?
Lewis TOwnsend


_______________________________________________________________
Get Free Email and Do More On The Web. Visit http://www.msn.com

new topic     » goto parent     » topic index » view message » categorize

3. Re: Procedures and Parameters

Ferlin Scarborough wrote:

<snip>

With a typical adventure parser, you typically only need three variables:
verb, noun, and with. Typically, it's the job of the parser to fill in these
values:

   look:
      verb = look
      noun = null
      with = null

   look at the vase
      verb = look
      noun = vase
      with = null

   look at the delicate ming vase
      verb = look
      noun = vase
      with = null

   look at the delicate ming vase with the magnifying glass
      verb = look
      noun = vase
      with = magnifying_glass


I'd just stick the values in global variables.

It's also typically the job of the parser to dis-ambiguify input text. Some
games are really stupid about this. For example, I've played games where
there are no keys in the room, but I can still type:

   > TAKE THE KEY

and the game will respond:

   Which key do you mean, the gold or the silver key?

The over-helpful parser (like the one above) gives away too many clues. Even
worse, there is the parser can't figure out what you mean, even if only one
choice makes sense:

   > OPEN THE DOOR WITH THE KEY
   Which door do you mean, the red or the green door?
   [parser doesn't notice there is only a GREEN door in the room]

   THE GREEN DOOR
   Huh?
   [parser requires full sentance be re-typed]

   > OPEN THE GREEN DOOR WITH THE KEY
   Which key do you mean, the gold or the silver key?
   [parser doesn't notice i only have SILVER key]

   > OPEN THE GREEN DOOR WITH THE SILVER KEY

These sorts of parsers make game playing painful.

-- David Cuny

new topic     » goto parent     » topic index » view message » categorize

4. Re: Procedures and Parameters

Ferlin:
   You actually want capture the whole line.
   Then break the line into tokens ( words )
   You are really writing an interpeter.

   If look(token) followed by end of the line.
        then do look
   elsif look(token) followed by at(token) followed by end of the line.
        then do look at
   elsif look(token) followed by up(token)followed by end of the line.
        then look up
   elsif etc
        then etc
   else
        Did not understand command
   end if

   Because you will have a lot of commands you should build a tree
   and follow the tree as you get the tokens.
Bernie

new topic     » goto parent     » topic index » view message » categorize

5. Re: Procedures and Parameters

Lewis Townsend wrote:
>
> Hello Ferlin,
>
> procedure Look (object thing)
>   puts (1, "blah blah")
> end procedure
>
> if equal (input_string, "look") then
>   Look (0)
> elsif equal (input_string[1..5], "look ") then
>   Look (input_string [6..length (input_string)])
> end if
>
> how's this?
> Lewis TOwnsend
>
> _______________________________________________________________
> Get Free Email and Do More On The Web. Visit http://www.msn.com

Lewis,

        I'll look this over and see what it will take to adapt it to
work in my engine code, one thing is this situation I was giving is
just one of DOZENS of procedures I am facing this situation with.
Thanks
for the input.

Later,

--
+ + +  Rev. Ferlin Scarborough  -  Centreville, Alabama  -  USA

          http://sites.netscape.net/fscarborough/homepage

MailTo:ferlin at sandw.net
MailTo:ferlin at email.com
MailTo:fscarborough at netscape.net

new topic     » goto parent     » topic index » view message » categorize

6. Re: Procedures and Parameters

On Mon, 26 Jul 1999, you wrote:
> All,
>
> The problem here is this, if define the Look procedure in the
> following manner to handle input such as look
>
> global procedure Look()
>     ..........
>     puts(You look.......
> end procedure
>
> and the user enters   look vase   then the program aborts
> with the following message:
>
> Syntax error - expected to see possibly ')', not a variable
>
> If I define the Look procedure in the following manner
> to handle input such as     look vase
>
> global procedure Look( sequence Obj)
>     ...........
>     puts(You look........
> end procedure
>
> and the user enters   look   then presses return the
> program aborts with the following message:
>
> Look() needs 1 arguments, not 0

> Is there a better more efficient way to handle this?
>
I think you may as well go ahead and write a command parser, you will be
calling it from all over your program. That way, one function can handle valid
and invalid inputs appropriately. You'll need a small dictionary of nouns and
verbs, and set up some simple syntax rules:  i.e. "vase look" could return a
"sorry, don't know how to vase",  while "look vase" returns "You are looking
at",  & "a blue vase"....  You may also want to set up tables of attributes -
so "take house" returns a smart alek remark, rather than "you are carrying a
vase and a house"....

Irv

new topic     » goto parent     » topic index » view message » categorize

7. Re: Procedures and Parameters

Just a follow up on the parser.

There are quite a number of parsers available, such as:

   Adventure Builder
   Adventure Game Toolkit
   ALAN
   Hugo
   Inform
   Quest
   TADS

You can find links to these (and others) at:

   http://interactfiction.about.com/msubtool.htm?pid=2752&cob=home

Most of these have manuals that go into great detail on how the toolkits
work. You'll probably save a lot of time and effort in re-inventing the
wheel if you see how these programs solve the various problems you are
facing.

-- David Cuny

new topic     » goto parent     » topic index » view message » categorize

8. Re: Procedures and Parameters

Lewis, Irv, Bernie and Dave,

        Thanks for the input, I already have the parser ALMOST working
that removes un-needed words such as AT and THE and so on.  I have been
thinking along the Tokens line.  Right now I have a table so to speak
that
contains Input_Procs = {"look", "do_look"},
                       {"eat", "do_eat"}
and so on, I borrowed this from EUSERVE and have implemented this code
already, I am implementing routine_id to point to the procedures, such
as do_look() and do_eat, these things work fine, I was just having
problems trying to decide HOW to use do_look for any situation with look
in it.  I will study all the responses I have received from all of you,
and maybe it will strike me as to what is the best procedure for
handling these routines.  Hopefully I will get some spare time in the
next few days to hack at it some more.

        One thing I have discovered is....MAN there is a lot of things that go
into writing a parser, but it has been VERY educational, as far as
implementing Euphoria.  I see that Euphoria is a Natural for a game
parser.  After I get the Text version up to speed, I intend to start on
a Sound and Graphics version.

Later,


--
+ + +  Rev. Ferlin Scarborough  -  Centreville, Alabama  -  USA

          http://sites.netscape.net/fscarborough/homepage

MailTo:ferlin at sandw.net
MailTo:ferlin at email.com
MailTo:fscarborough at netscape.net

new topic     » goto parent     » topic index » view message » categorize

9. Re: Procedures and Parameters

Hello,

Ferlin wrote:
>Lewis,
>
>         I'll look this over and see what it will take to adapt it to
>work in my engine code, one thing is this situation I was giving is
>just one of DOZENS of procedures I am facing this situation with.
>Thanks
>for the input.
>
>Later,
>
>--
>+ + +  Rev. Ferlin Scarborough  -  Centreville, Alabama  -  USA

I think David has the right idea. I've never done anything like this before.
I, of course, have lots of my own ideas but never know if they are any good
unless I try them out.

Lewis Townsend


_______________________________________________________________
Get Free Email and Do More On The Web. Visit http://www.msn.com

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu