commands on what?!?

XanMag
21 Dec 2015, 03:51
So, I totally understand adding commands to a room. Easy.

But, how do commands on objects work?

For example, here is code I am trying to use in my tutorial game:

      <command name="fill pot cmd">
<pattern>fill pot with water; fill pot from waterfall; put pot in waterfall; put pot under waterfall; use pot on waterfall; use pot under waterfall; hold pot under waterfall; fill pot with waterfall; fill pot</pattern>
<script>
if (GetBoolean(jug, "filled")) {
msg ("You can only have one container filled at a time.")
}
else if (GetBoolean(bucket, "filled")) {
msg ("You can only have one container filled at a time.")
}
else if (GetBoolean(pot, "filled")) {
msg ("You can only have one container filled at a time.")
}
else {
msg ("You hold the pot under the flowing waterfall until it is filled.")
MoveObject (water1, pot)
SetObjectFlagOn (pot, "filled")
}
</script>
</command>


This command script is on the object pot. But it does not return my responses, only "I don't understand your command." I know I can put this command on the 'room' and it will work, but let's say there is another waterfall in a different room. I'd like the command to follow around the pot and not be restricted to a room. I also know I can use all sorts of "If" player is carrying object bucket, "then" "if" object waterfall is visible, "then" follow said script, but that just seems like unnecessary coding. I also know that I can copy-paste each command into any room with a 'waterfall' in it, but what about commands on objects that can be moved around room to room? Is the easiest way to make a complicated if/then/if/then script and make it global? Ugh...

<command name="water to jug cmd">
<pattern>pour water into jug; transfer water to jug; put water in jug; transfer water to jug; pour water in jug</pattern>
<script>
if (GetBoolean(pot, "filled")) {
msg ("You pour the water from the pot into the jug.")
SetObjectFlagOn (jug, "filled")
SetObjectFlagOff (pot, "filled")
}
else if (GetBoolean(bucket, "filled")) {
msg ("You pour the water from the bucket into the jug.")
SetObjectFlagOn (jug, "filled")
SetObjectFlagOff (bucket, "filled")
}
else if (GetBoolean(jug, "filled")) {
msg ("The jug already contains the water.")
}
else {
msg ("There is no water in a container to be poured into the jug. You need to fill one from the waterfall first.")
}
</script>
</command>


So, where should I put the command in a case like this? FYI, I have a 15-20 commands I would like to add to X2 that are similar.

george
21 Dec 2015, 06:29
Maybe you want a verb instead?

viewtopic.php?p=12268#p12268

XanMag
21 Dec 2015, 06:39
But, can you link multiple objects with one verb on one object? For example, 'watch ship with spyglass'. Or, in my example above 'pour jug into bucket'. Or, from X2, 'put poison on wrench' vs. 'put bottle on wrench' vs. 'put bottle in wrench' vs 'put poison in wrench' vs. 'put rat poison on wrench'. Where would I put a verb in those conditions and how would I word it? That seems like a job for a command, right?

The Pixie
21 Dec 2015, 08:47
XanMag wrote:...
This command script is on the object pot. But it does not return my responses, only "I don't understand your command."

The "I don't understand your command." response indicates it has not matched what the player typed with your command. I have pasted your pattern into a test game on my PC, and it gets recognised, so this is... odd. The only thing I can think of is that you have another command with the same name somewhere else in the game, and the other command is over-writing this one.

I know I can put this command on the 'room' and it will work, but let's say there is another waterfall in a different room. I'd like the command to follow around the pot and not be restricted to a room. I also know I can use all sorts of "If" player is carrying object bucket, "then" "if" object waterfall is visible, "then" follow said script, but that just seems like unnecessary coding. I also know that I can copy-paste each command into any room with a 'waterfall' in it, but what about commands on objects that can be moved around room to room? Is the easiest way to make a complicated if/then/if/then script and make it global? Ugh...


The way I would do it is this:

Any room with a waterfall (or similar), add a Boolean flag called "watersource", and set it to true.

Any item that can be filled (the pot, jug, etc.), add a boolean flag called "filled", and set it to false.

For your command, use #object# to match against any object present.
      <command name="fill pot cmd">
<pattern>fill #object# with water; fill #object# from waterfall; put #object# in waterfall; put #object# under waterfall; use #object# on waterfall; use #object# under waterfall; hold #object# under waterfall; fill #object# with waterfall; fill #object#</pattern>
<script>
// first check if this object can be filled
if (not HasBoolean(objected, "filled")) {
msg ("That is not something you can fill with water.")
}
// now check if it is already full
else if (GetBoolean(jug, "filled")) {
msg ("It is already full of water.")
}
// is there water to fuill it from?
else if (GetBoolean(player.parent, "filled")) {
msg ("There is no waterfall here.")
}
// all checked okay, so do it
// use GetDisplayName to handle objects with and without alias
else {
msg ("You hold the " + GetDisplayName(object) + " under the flowing waterfall until it is filled.")
MoveObject (water1, object)
SetObjectFlagOn (object, "filled")
}
</script>
</command>

Marzipan
21 Dec 2015, 09:11
Might not be exactly what you're looking for, but you can put a 'fill' verb on a bucket, invisible 'watersource' objects in certain rooms, and just put if-thens on the bucket checking if any of the water sources are visible.

I'm sure there are more elegant solutions, but this lets you avoid going around putting scripts on every water source or worrying about whether the player is even holding the bucket.


e: I'll add though, that instead of trying to match every possible command the player might try, you might consider just having a line in the bucket's description, 'You could fill this from a water source.' As a player, sometimes it's appreciated having the guesswork on a verb removed in a nice straightforward way. :)

XanMag
21 Dec 2015, 21:22
Okay... So what about two objects I can carry around and use anywhere in my game? Can commands be placed on rooms or the game only? I am leaning toward using commands for manipulating objects with other objects because I think they're way more versatile but constantly writing scripts checking if the player has this and has that object is tedious. The more I think about it, I think the only option is to use commands and then check and check to see if the player is carrying those objects. Unless I'm missing something about command usage.

Can commands be placed on objects?
Is there a simpler way?

jdpjdpjdp
22 Dec 2015, 00:51
Verbs have the "require another object" option, which you might find useful for some of the described scenarios. Another option is to task the commands to "use". You'd set up a regular "use x on y" relationship, say "use bucket on waterfall". Then you create a regular, game-wide command where "fill bucket from waterfall" or "put bucket under waterfall" or "whatever I want to type here" calls the "HandleUseOn" function with parameters "bucket" and "waterfall". It's a nice little shortcut cheat I use sometimes.