Command Patterns

Enpherdaen
24 Sept 2016, 20:18

I was just wondering if there is a way to make different texts enable the same custom command. I know you can just add an entirely new copy of the same command multiple times and use a different name for each, but that take a while and is extremely annoying.


hegemonkhan
24 Sept 2016, 20:40

could you explain in more detail at what you're asking for/about and/or what you want to do? As I'm not quite clear of what you're asking about.


Commands are known (best) by (having) their (an) unique first word ("activator/identifier word") in their patterns, so you don't have any parsing issues, for examples:

<command name="kick_command">
  <pattern>kick #object_parameter_1#</pattern>
  <script>
    msg ("You kick the " + object_parameter_1 + ".")
  </script>
</command>

<command name="kiss_command">
  <pattern>kiss #object_parameter_1#</pattern>
  <script>
    msg ("You kiss the " + object_parameter_1 + ".")
  </script>
</command>

if I input 'kiss toad', there's no confusion, the 'kiss_command' Command will be the activated/used Command
if I input 'kick toad', there's no confusion, the 'kick_command' Command will be the activated/used Command

---------------------------------------

however, if I had these Commands' Patterns:

<command name="say_command">
  <pattern>say #text_parameter_1#</pattern>
  <script>
    msg ("You say aloud \"" + text_parameter_1 + ".\"")
  </script>
</command>

<command name="say_to_command">
  <pattern>say #text_parameter_1# to #object_parameter_1#</pattern>
  <script>
    msg ("You say \" + text_parameter_1 + "\" to " + object_parameter_1 + ".")
  </script>
</command>

if I input:

say hi to bob

and pretending my example is a good/working example, lol - not sure if it is a good/working example, then:

it is uncertain which Command will be activated, as it could be either of them, producing either of these two results/displayments/outputs (a demonstration of the parsing issue with not using unique first words in the Commands' patterns):

You say aloud "hi to bob." // the 'say_command' Command
VS/OR
You say "hi" to bob. // the 'say_to_command' Command

you can give the Command multiple/alternative patterns simply by using a semicolon in the Command's 'pattern' box:

Command Pattern: talk to #object#; speak to #object#; say to #object#; etc etc etc


Enpherdaen
24 Sept 2016, 21:54

Thanks a lot laddy. :D


Enpherdaen
24 Sept 2016, 21:57

I'll give you an example: "Put ammuntion in gun, load revolver, use ammunition, load gun," etc. They all mean the same thing so, I'd like to make all of them activate the same command.


hegemonkhan
25 Sept 2016, 05:53

Command Pattern box:

put ammunition in gun; load revolver; use ammunition; load gun


DillonJHonore
12 Oct 2016, 02:40

What exactly does a "command pattern" do? (I know, I'm a noob, but I still want to know)


hegemonkhan
12 Oct 2016, 18:10

The Command's 'pattern' is the structure/format that is used for parsing (string/text matching) the user's typed-in input during game play for selecting, activating, getting data for its use, and executing, of Commands.

for example (in code):

<command name="you_say_hi_command">
  <pattern>hi</pattern>
  <script>
    msg ("You say hi.")
  </script>
</command>

when the person playing the game, types in 'hi', the 'you_say_hi_command' is run/activated/executed.


it's important to have a unique 'first word' (what I like to describe as the 'activator word') for your Command's pattern, so that there won't be any problems with quest trying to parse (determine) what Command to run/execute.

for example:

command name="you_say_hi_command">
  <pattern>hi</pattern>
  <script>
    msg ("You say hi.")
  </script>
</command>

command name="you_say_bye_command">
  <pattern>bye</pattern>
  <script>
    msg ("You say bye.")
  </script>
</command>

quest will not be confused, if/when you type in 'hi', as it is clear for it to run the 'hi' Command. And if/when you type in 'bye', it is clear to run the 'bye' Command.

however, this is not clear, which Command to run:

<command name="you_say_hi_command">
  <pattern>hi</pattern>
  <script>
    msg ("You say hi.")
  </script>
</command>

<command name="you_say_bye_command">
  <pattern>hi</pattern>
  <script>
    msg ("You say bye.")
  </script>
</command>

when you type in 'hi', quest (and people too) will have no idea which Command you wanted to select for activation/running. Does it run the 'hi' Command or does it run the 'bye' Command ???

you got to make your Commands' 'patterns' unique enough that they can be distinguished from one another, so that quest knows which one to run.


more examples of a Command's usage/features/abilities:

<command name="say_hi_to_inputed_value_command">
  <pattern>hi #object_parameter_1#</pattern>
  <script>
    msg ("You say hi to " + object_parameter_1.name + ".")
  </script>
</command>

<object name="room">
  <object name="player">
  </object>
  <object name="bob">
  </object>
  <object name="bill">
  </object>
</object>

now, if 'bob' and 'bill' were Objects within the same room as you, if you type in:

hi bob
// Output: You say hi to bob.

hi bill
// Output: You say hi to bill.

you can use as many:

#textXXX# and/or #objectXXX# parameters as you like:

(you must have the parameters' names/labels start as: '#text' or #object', and end as: '#', within the Command's pattern, and then within the scripting you just leave off the '#' characters/symbols)

<command name="mix_command">
  <pattern>mix #text1# #text2# #text3#</pattern>
  <script>
    msg ("You mix: " + text1.name + ", " + text2.name + ", and " + text3.name + ".")
  </script>
</command>

if you type in:

mix toad frog turtle
// output: You mix: toad, frog, and turtle.


The Pixie
12 Oct 2016, 20:49

when you type in 'hi', quest (and people too) will have no idea which Command you wanted to select for activation/running. Does it run the 'hi' Command or does it run the 'bye' Command ???

Quest will run the bottom one. This is important because it allows creators to override the built-in commands, which are right at the top. Also, you should put more specific commands below more general ones.


hegemonkhan
13 Oct 2016, 07:22

ah, didn't know that. Thanks Pixie for correcting me and explaining (whether HK can remember/recall this info is another matter).

hmm, maybe then this example would better illustrate the parsing issue of that people have to be careful with for their patterns:

<command name="say_command">
  <pattern>say</pattern>
  <script>
    msg ("hi")
  </script>
</command>

VS

<command name="say_to_command">
  <pattern>say #object#</pattern>
  <script>
    msg ("hi, " + object.name + ".")
  </script>
</command>

The Pixie
13 Oct 2016, 10:25

I have been looking at how commands are resolved:
https://github.com/ThePix/quest/wiki/Pattern-Matching-with-Regular-Expressions

It is more complicated than I thought, and in fact your say_to_command will win whether it is first or second because its match strength is higher. This is the number of matched characters outside the #object#, #text#, etc., so 4 for that and 3 for say_command.

That said, I think patterns have implicit anchors so the first will only match SAY, not SAY PIXIE; the second will not match SAY, but could match SAY PIXIE.


hegemonkhan
13 Oct 2016, 20:52

ah, so the match strength testing uses priorities (number of matching words: more=greater priority; less=lesser priority) along with its parsing, and I'm still working on understanding your second part, lol.


the programming class I'm taking right now is teaching this stuff (data structures/management):

queues, stacks, lists/arrays, dictionaries, priorities, linked lists, nodes, trees, heaps, grammers, axioms, etc

though, it's new stuff for me, so I'm struggling a bit with understanding it (I get the concepts pretty easily so far, but have trouble with what syntax/code is needed, along with the OOP/OOD --- it just confuses my brain --- can't keep track of stuff and/or how it all works together, etc etc etc --- as I've never really done OOP/OOD, so my brain isn't trained in this type of thinking and etc)