ainslec / adventuron-issue-tracker

Adventuron Issues Tracker
4 stars 0 forks source link

Feature Request: Multi parse or issuing a command to an NPC #43

Open ainslec opened 4 years ago

ainslec commented 4 years ago

Adventuron only parses the command input once currently. It can queue commands deliminated by a full stop, but each command can only consist of the following elements:

verb, adverb, noun1, noun2, adjective1, adjective2, preposition, noun3, adjective 3.

noun3and adjective3 are special and is only parsed after "except".

noun3 example:

get everything from the drawer except the pencil

everything = noun1 drawer = noun2 except = noun3

Sometimes a player might want to type something like

Either Adventuron should support verb0 "say" and noun0 "mike", or it should support multi parsing, where the quoted sentence is saved, and can be parsed lazily in a command handler.

ainslec commented 4 years ago

Added initial support as this, treat this as experimental and subject to change for now:

start_at = my_location

locations {
   my_location : location "You are in a room with the ranger." ;
}

on_command {
   // Matches the following...

   // Say to ranger, throw rope.
   // Hey ranger, throw me the rope.
   // ranger, throw me the rope.
   // ranger throw rope

   // it does not yet currently match, ranger "throw rope" (double quotes not dealt with yet)

   : if (noun0_is "ranger" && (verb0_is "say" || verb0_is "")) {
      : match "- -"  {
         : print "Eh? ... says the ranger." ;
         : done ;
      }
      : match "throw rope" {
         : print "The ranger throws the rope";
      }
   }
}
hnejfnvjojgrogjwm commented 4 years ago

I have an issue with this new system, when the string doesn't contain a verb. e.g.:

: match "_ house" { : print "The ranger tells you about the house"; }

This doesn't work and the error message is "You can't do that".

hnejfnvjojgrogjwm commented 4 years ago

And another issue found: Run the code on the original post and type: SAY RANGER I

ainslec commented 4 years ago

I have an issue with this new system, when the string doesn't contain a verb. e.g.:

: match "_ house" { : print "The ranger tells you about the house"; }

This doesn't work and the error message is "You can't do that".

Please show me a full code snippet, plus the inputs you are using that fail.

ainslec commented 4 years ago

And another issue found: Run the code on the original post and type: SAY RANGER I

There isn't a bug in adventuron here, but sorry, there is a bug in the sample code I posted.

: match "- -" { // will match when verb1 and noun1 are blank }

: match " " { // Will match when verb and noun are blank or not blank }

So the code snippet should be :

locations {
   my_location : location "You are in a room with the ranger." ;
}

on_command {
   // Matches the following...

   // Say to ranger, throw rope.
   // Hey ranger, throw me the rope.
   // ranger, throw me the rope.
   // ranger throw rope

   // it does not yet currently match, ranger "throw rope" (double quotes not dealt with yet)

   : if (noun0_is "ranger" && (verb0_is "say" || verb0_is "")) {

      : match "throw rope" {
         : print "The ranger throws the rope";
        : done;
      }
      : match "_ _"  {
         : print "Eh? ... says the ranger." ;
         : done ;
      }
   }
}
hnejfnvjojgrogjwm commented 4 years ago
start_at = my_location

locations {
   my_location : location "You are in a room with the ranger." ;
}

on_command {

   :match"_ house"{
      :print"Something about the house.";
   }

   : if (noun0_is "ranger" && (verb0_is "say" || verb0_is "")) {
      : match "throw rope" {
         : print "The ranger throws the rope";
         : done ;
      }
      : match "paint wagon" {
         : print "The ranger paints his wagon";
         : done ;
      }
      : match "_ house" {
         : print "The ranger tells you about the house";
         : done ;
      }
      : match "_ car" {
         : print "The ranger tells you about the car";
         : done ;
      }
      : match "come _" {
         : print "The ranger follows you";
         : done ;
      }
      : match "_ _"  {
         : print "Eh? ... says the ranger." ;
         : done ;
      }
   :done;}
}

Type: SAY RANGER HOUSE Answer: Something about the house. Expected answer: The ranger tells you about the house

Type: SAY RANGER CAR Answer: You can't do that. Expected answer: The ranger tells you about the house

ainslec commented 4 years ago

Adventuron now has a verb noun prefix mechanism (for qualifying languages - which is currently Spanish and English):

(Ignoring directions & ignoring non dictionary words) :

There is a concept now in Adventuron of the pre-sentence, and the proper-sentence.

The pre-sentence is scanned for verb0 and noun0, and the proper sentence is scanned for verb1, adjective1, noun1, adjective2, noun2, adverb, preposition.

If a sentence starts in a verb then the pre-sentence will not be scanned. If the sentence starts in a noun or a COMMAND VERB, then the pre-sentence will be scanned. A command verb is something that is interpreted to be a command. To derive this, adventuron uses the verb0_is condition to work out what is being considered as a command verb. No need to configure a verb if it is referenced in such a way.

The pre-sentence may evolve over time to scan for more types of words, but currently it serves the purpose of supporting issuing commands to NPCS.

For example (assuming that 'hey', 'me', 'the' are not dictionary words, and 'to' is a preposition:

> hey ranger, give me the boots

noun0 = ranger ,verb1 = give, noun1 = boots

> ranger, give me the boots

noun0 = ranger ,verb1 = give, noun1 = boots

> ask the ranger, to give boots

verb0 = ask, noun0 = ranger ,verb1 = give, noun1 = boots

> ask ranger for boots

verb0 = ask, noun0 = ranger ,verb1 = give, noun1 = boots

> ask ranger for the boots

verb0 = ask, noun0 = ranger , noun1 = boots

If a sentence starts with a noun, then the noun will be matched as noun0, and everything after it is the real sentence. If a noun is also an adjective, then test to see if there is another noun, and if there is everything after that noun is part of the real sentence. If a sentence starts with a command verb (a verb that is referenced by verb0_is "" somewhere in the code), then match that verb as verb 0, then everything between that verb and the next verb will be scanned for noun0, then subsequent words will be interpreted as the real sentence proper.

This is a first pass at the command issuing mechanism. It might be troublesome to cover all the patterns that the player can type, but generally speaking, you only need to support this kind of grammar pattern once or twice in a given game,

The role of the word 'for' is in question, as in many contexts it means give, if the preposition comes first in the proper sentence. Dealing with leading propositions in a proper sentence following a pre sentence and implying a verb from a leading proposition is something that needs to be considered.

The burden for all this special case logic should not be on the game author.

ainslec commented 4 years ago

Here is how NPC commands is anticipated to be structured in the on_command {} section:

on_command {

   : if (verb0_is "say" || noun0_is "" == false) {
      // handle your NPC commands here....
      : gosub "npc_conversation";
      : print "You say something but no-one responds";
      : done;
   }

   // Your non-NPC responses here (anything without a noun0 or verb0)
}