Command scope and unresolved text

Could some kind person explain to a non coder in simple terms how to use command scope .
I want player to be carrying the object Box and see object Front door to use the command. I suppose I could use if / else but I find that too complicated with multi options. I always end in a muddle.


Are both the box and the door mentioned in the command the player will be typing?

If you have two objects in different scopes for a command, the scope will be a little more complex.

For example, if the command you are looking for is "throw box at door", and your throw command has the pattern throw #object1# at #object2#, then you could give it the scope object1=inventory|object2=room to indicate that this command is used to throw an object in the inventory at an object in the room.

However, if the player types the full name of an object that is in the wrong scope, the command will still run. So you will still need to have a few if statements in the command's script to make sure that the player is trying to do something sane. A common way to do this would be to check the possible error conditions one by one, and use the else clause for actually running the command. For example:

if (not Got (object1)) {
  // Object1 isn't in the inventory
  msg ("You can't throw something you don't have")
}
else if (Got (object2)) {
  // object2 is in the inventory
  msg ("I can't throw it into my pocket")
}
else if (not object1 = box) {
  // trying to throw the wrong object
  msg ("that's too valuable to throw")
}
else if (not object1 = door) {
  // trying to throw at the wrong object
  msg ("that doesn't seem like a good place to throw it")
}
else {
  // nothing's gone wrong, so we do the command
  msg ("You throw it at the door. Something happens.")
  // whatever other scripts you need to do here
}

On the other hand, if the objects are used implicitly, then those if statements are all you need.
For example, in my remake of 'Circus', there is a command "syphon fuel" which you can only do if you have a snorkel and are in the same room as the generator. That command's scope is simply "room", because the only object mentioned in the command is 'fuel', which needs to be in the room. The snorkel isn't mentioned in the command the player types, so the scope ignores it.


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

Support

Forums