[SOLVED and useful!] Complex Commands

XanMag
I'm kind of fiddling with some stuff in my GUI-tutorial game and need a little help.

I'll apologize for the redundancy (a similar post is over in the libraries under ThePixie's 'Complex Commands').

In one room in my tutorial I am showing three different ways to use two objects together - verbs, command patterns, and regular expressions. The verbs are easy. Done. The command pattern is done. Now, using some fancy code supplied by The Pixie in the above mentioned library, I have gotten this code to work in X3 --> ^(tell|ask) (?<object>.*) to (be quiet|keep quiet|shut up|hush|be silent)$

In my tutorial game, I have tried that again...

I used this --> ^(pour|dump|add|empty|put|use) (the |) (?<object_water>.*) (on|over|into|onto) (the |) (?<object_seedling>.*)$
... a little more complex, but I think it is correct.

Below is the code for this section of my tutorial:

<command name="water seedling cmd">
<pattern type="string"><![CDATA[^(pour|dump|add|empty|put|use) (the |) (?<object_water>.*) (on|over|into|onto) (the |) (?<object_seedling>.*)$]]></pattern>
<script>
if (Got(water)) {
if (ListContains(ScopeVisible(), seedling)) {
msg ("You empty the water onto the plant. It is quickly absorbed by the ground! Within minutes, the ground rumbles and a giant apple tree emerges from the earth!")
MakeObjectInvisible (water)
MakeObjectInvisible (seedling)
MakeObjectVisible (apple tree1)
}
else {
msg ("There is no seedling here to water!")
}
}
else {
msg ("You need to be carrying the water to do that.")
}


I thought that ^(pour|dump|add|empty|put|use) (the |) (?<object_water>.*) (on|over|into|onto) (the |) (?<object_seedling>.*)$ would accommodate all of the combinations - pour water on seedling, use water on the seedling, empty water on seedling, etc. When I try to 'use water on seedling' I get the message 'You can't use it that way' and if I use other combinations like 'pour water on seedling', I get the message 'I can't see that. (water on seedling)'

Does anyone know what the deal with this is?

Thanks in advance!

Pertex
XanMag wrote: When I try to 'use water on seedling' I get the message 'You can't use it that way'


I think the build-in use command is 'stronger' than your command.

XanMag wrote:and if I use other combinations like 'pour water on seedling', I get the message 'I can't see that. (water on seedling)'


THere are too many blanks in your expression. Try this ( I removed a blank after (the |) )

<pattern type="string"><![CDATA[^(pour|dump|add|empty|put|use) (the |)(?<object_water>.*) (on|over|into|onto) (the |)(?<object_seedling>.*)$]]></pattern>

XanMag
Unreal. I don't know how you and others understand or notice that little error... I could have search infinitely and I still would have been clueless!

but, it works like a charm now, even the 'use' part of that!

Thanks!

HegemonKhan
It's more (and difficult) to program into the language~software parsing that also handles spaces in people's code lines, so generally if you want to be safe, don't use spaces, as not every software or language is as well programmed as quest such as for handling the use of spaces by people in their code lines.

also, be careful, when you highlight-copy-paste, laughs, as you could accidentally highlight and copy a space... and be pulling your hair out for days in trying to figure out why something is not working!

(space)game.strength =/= game.strength
game.strength(space) =/= game.strength

super annoying mistake that is so hard to realize~discover~find, so be UBER careful when highlighting-copying-pasting stuff, that you don't highlight and copy-paste unwanted spaces to the left or right of what you want to copy-paste!

XanMag
Help me out here, please. I thought I had this correct, but the below 'regular expression' I is recognizing (?<object_water>.*) and (?<object_seedling>.*) as any objects. How can I change it to only have the water and the seedling recognized? If I type in 'use seed on seed' for example, it will carry out the script attached to this command.

^(pour|dump|add|empty|put|use) (the |)(?<object_water>.*) (on|over|into|onto) (the |)(?<object_seedling>.*)

I've changed it to this... and it appears to be working.

^(pour|dump|add|empty|put|use) (the |)(bottle|water|bottle of water) (on|over|into|onto) (the |)(seedling)

I guess I would just like clarification as to what (?<object_water>.*) means... =)

Sorry for the dumb question! And, thanks!

The Pixie
(?<object_water>.*) will get matched against any object in scope. If the player types POUR THE SEEDLING OVER THE GROUND, then is will get matched against seedling, and in your code, the variable object_water will be the seedling object.

The best way (IMO) is to test the objects.
if (not object_water = water) {
msg("You can't pour that over stuff.")
}
else if (not object_seedling = seedling) {
msg("You can't go around pour water over stuff like that!")
}
else {
..etc

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums