Complex Commands
XanMag
24 Mar 2018, 22:41^(get|pick up|take) (?<object1>.*) (using|holding|with) (the |)(?<object2>.*)$
From what I understand, this will take whatever follows the first word (get|pick up|take) and reference whatever the second word is (object1) as the noun.
If I want object1 to be something specific, like 'bucket', do I do (<bucket>)
? or what?
I know that's a dumb question, but I yam what I yam... Thanks!

K.V.
25 Mar 2018, 00:05To warn you up front, I don't know what will happen if you enter an object other than bucket*, but here's the code (untested):
^(get|pick up|take) (?<object1>bucket) (using|holding|with) (?<object2>.*)$
Or did I get that backwards? Do you want to pick up something with the bucket?
^(get|pick up|take) (?<object1>.*) (using|holding|with) (?<object2>bucket)$
* If you specify the object in the command pattern, using any other object in that place will output:
I can't see that.
You'd be better off with this, then checking the input in the command's script:
^(get|pick up|take) (?<object1>.*) (using|holding|with) (?<object2>.*)$
if (not object2 = bucket) {
msg("You can't do that.")
}
else {
// Do the damn thing.
}
NOTES:
The difference between these two?
^(get|pick up|take) (?<object1>bucket) (using|holding|with) (?<object2>.*)$
^(get|pick up|take) bucket (using|holding|with) (?<object2>.*)$
Using the former, the player could enter:
GET BUCK WITH HOOK
or
GET THE BUCKET WITH THE HOOK
Using the latter, they would have to specifically start with:
GET BUCKET ...
or
PICK UP BUCKET ...
or
TAKE BUCKET ...
Using the regex capture (?<object>bucket)
will allow the object to be matched to its alternates (or synonyms, or whatever), just like commands normally would.
Also, when using regex capture, you don't need (the|)
in front of an object capture, since Quest will weed that out anyway.

Doctor Agon
25 Mar 2018, 00:19Hi,
(?<object1>.*)
is equivalent to #object1#; in a regex it is called a “capture group, because it groups some characters together, and captures them for use elsewhere.
So, if you want your object1
to be something specific, like a bucket you'd just put that into the expression instead.
eg:
Regular Expression
^(get|pick up|take) (?<object_bucket>.*) (using|holding|with) (the |)(?<object2>.*)$
See link: (which someone called XanMag features)
https://textadventures.co.uk/forum/samples/topic/5862/complex-commands
http://docs.textadventures.co.uk/quest/complex_commands.html
XanMag
25 Mar 2018, 00:40I guess I probably should go with the (?<object1>.*)
because using Agon's method I would not be able to account for all other objects, right? And, I'd still have to use an 'If' script to deal with whatever object 2 is. If I understand that right, I'll apologize now for being a little bit...
https://www.youtube.com/watch?v=KWYAuxBgk_0

K.V.
25 Mar 2018, 00:47I'd definitely just use (?<object1>.*)
and (?<object2>.*)
, then do everything in the script.
The Pixie
25 Mar 2018, 09:05Keep the pattern as it is, but check if object1 is the bucket in code. You can then set synoyms for the bucket, like pail, on the bucket object, and the command will still work.
if (not object1 = bucket) {
msg("You need a bucket to do that."
}
else {
...
}
mrangel
25 Mar 2018, 13:38There are two stages to command parsing. First the regex pattern, then after that is executed, it checks all capture groups whose names start with "object" or "exit" to make sure that a matching object is in the room.
So if you put pass (?<object>bucket)
and the player types "pass buck", the regular expression won't match. It will act like the command didn't exist.
(In your example with 'get', this command would fail to match and it would fall back on the default 'get' command. So if you type "get water with buck", it then tries to find an object named "water with buck" and responds "I can't see that")
In some cases, it may be important to watch out for this two phase execution. One thing I noticed in your initial pattern:
^(get|pick up|take) (?<object1>.*) (using|holding|with) (the |)(?<object2>.*)$
is that you need to be careful you don't have any objects whose aliases contain the words "using", "holding", or "with".
For (a rather silly) example:
==> get bucket using string with a hook on the end
That matches the pattern. It populates the variables with: object1 = "bucket using string"
and object2 = "a hook on the end"
. Then it compares these two strings against the command's scope to convert them into object, finds nothing, and tells the player "I can't see that".
(In that example, you could make it work using (?<object1>.*?)
- which means that object1 ends with the first instance of 'with', 'using', or 'holding' rather than the last. But that would be a problem if the player wanted to use an object containing one of those as the first parameter)