Make objects unusable while a state is in play

Hello everyone. I'm relatively new to this, and though I've read through the documentation I'm stuck on something. At different parts of the game (during fights for example) I'd like to make objects that you would usually be able to interact generate a different message (and keep you from using it) during this state. What's the best way of going out this? I've figured out how to close doors. (i just lock them during a particular state, and the make a trigger to unlock them after an action is done, though i wish I could make the doors have different outputs for every specific session). I am not sure how to do this with objects though, other than just making them invisible, which isn't really realistic (they are there you just shouldn't use them at the time). Any ideas?


Do you mean the "use" command, or an object's other verbs?

In either case, the script for doing that action is stored in a script attribute; so you can temporarily remove it.

An example script. To disable verbs:

// Which commands we want to disable
verbs_to_disable = Split ("use;useon;taste;paint")

// Only visible objects. Depending how far the player can move while this state is in effect, it might be better to use AllObjects()
objects_to_disable = ScopeVisible()
foreach (obj, objects_to_disable) {
  foreach (verb, verbs_to_disable) {
    if (HasAttribute (obj, verb)) {
      set (obj, "disabledverb_"+verb, GetAttribute (o9bj, verb))
      if (verb = "use") {
        // We handle 'use' differently from other verbs, because I think it can't be a string
        obj.use => {
          msg ("You can't do that right now!")
        }
      }
      else {
        set (obj, verb, "You can't do that right now!")
      }
    }
  }
}

And then to enable those verbs again, you'd do:

foreach (obj, AllObjects()) {
  foreach (verb, GetAttributeNames (obj, false)) {
    if (StartsWith (verb, "disabledverb_")) {
      set (obj, Mid (verb, 14), GetAttribute (obj, verb))
    }
  }
}

That just disables specific verbs for specific objects.
I can think of better ways to do that (for example, by making a 'disabledverbs' dictionary), but the code would be harder for you to see what I'm doing.


Or, a simpler method:

If you want to disable certain commands entirely, you could create a new command, with a pattern like use #text#;examine #text#;eat #text#;craft #text# - so that it matches all of the commands you want to block.

When you want to stop the player using those commands, you move your new command into the room with them; and when you want them to be able to act normally, you move the command into a box somewhere.

Commands which are in the current room always take priority over commands that don't have a specific location. And you can move commands around in a script just like you can with any other object.


Thanks so much! So the n00b in me is going to go for the simpler methods (especially since I don't even know how you get to the code mentions in the harder method.

I know how to create commands but I don't know how to tell the commands to enter or leave a room based on what's going on.

for example at the beginning of this game the player is in a fight. They can't use the exits, and they can't use the objects. They have to "fight" the person there, and THEN they can use the exits and interact with the environment. I can put the command in the room to stop them from doing these things at the beginning but say the action is "K.O. opponent" and I create a script to unlock the doors and remove the opponent from the room? How do I also remove the "block" command from the room?


Yeah I've been poking around for over an hour and there is no way to remove a command like you can an object (aside from code I'm guessing). It only lists non command objects when I try to "remove" script.


You should be able to use the 'move object' script on a command.

It only lists objects in the GUI editor, but if you select "expression" then you can type the name of the command in the box and it will work fine.

You don't want to 'remove' the command, however. The RemoveObject function moves an object into space (outside any room, where the player can't interact with it); but commands that aren't in a room are effective everywhere.
When you want to remove the command, you need to use the 'move object' function to put it inside an object somewhere; then it won't have any effect unless the player is also inside that object.

Alternatively, you can disable a command by changing its pattern attribute to the string ^(?!x)x (a special pattern which doesn't match any command)


AH I created an object called "Command Toybox" and moved the "Block During Fight" command there after the fight is over and SHIPOOPI it worked! That is glorious. I have a lot to learn but this will help quite a bit for future things. Thank you!


Log in to post a reply.

Support

Forums