Look at only and objeccts

GlueGunner4
27 Apr 2020, 02:56

I was making an escape room with look only exits to look left, right, etc. and when I look in a direction, the objects don't show up. I don't know why. Any Ideas?

EDIT: Maybe it's because the objects are under the look exit. But then how else am I supposed to only see the objects when I look in that direction?


mrangel
27 Apr 2020, 09:34

By default, a look-only exit doesn't show you objects in the other room. If you want to do that, the easiest way is to include the list of objects in the other room's description. Something like: {either not game.pov.parent=name of room:{=FormatObjectList("In the room you can see ", name of room, ".")}}.

If you want to change the behaviour of looking in a direction, so that you don't need to do it for each exit, you would need to replace the "lookdir" script. The desktop editor should allow you to copy and edit a core command; or if you're using the web editor you could change it from the start script like this:

lookdir.script => {
    if (HasScript(exit, "look")) {
        do (exit, "look")
    }
    else {
      message = DynamicTemplate("YouLooking",exit.alias)
      if (HasString(exit, "look")){
        if (exit.look <> "") {
          message = exit.look
        }
      }
      if (exit.locked) {
        if (HasString(exit,"lockmessage")) {
          lockmessage = exit.lockmessage
        }
        else {
          lockmessage = Template("LockedExit")
        }
        msg (message+" "+lockmessage)
      }
      else {
        msg (message)
        msg (FormatObjectList ("You can see ", exit.to, "."))
      }
    }
}

If you want the player to be able to reach objects through these exits (so they can use commands on them), you will also need to make the objects reachable. I would suggest making containers named "north wall", "east desk", or so on, and putting the objects inside them. You can change the "It contains" line to something more appropriate. You can make these objects 'scenery' if you don't want the game to list them as being in the current room.

In this case, typing "look east" will not see a container called "east wall", because the direction names are special and it will trigger lookdir. So you might still need to create a look-only exit pointing into the container. In this case, because the container is in the room, you could make the exit's look description a script:

do (lookat, "script", QuickParams ("object", this.to))

Which effectively makes "look east" a shortened form of "look at east wall". If you wanted to, instead of making the exits look-only, you could give them a look description like that and an exit script like:

msg ("You walk over to the north wall.")
do (lookat, "script", QuickParams ("object", this.to))

This means that if the player enters "go north", it will have the same effect as looking at the north wall. I like to follow the "principle of least surprise"; making all the commands that a player is likely to use effective.


(Actually, I'm a little unimpressed with the way scope works. We now have changescopescript, which gives finer-grained control than the backdrop scope script, but that doesn't help with all the core commands that check ScopeReachable() before doing their thing. I think I've got a neater way it could be implemented, but that would be a pretty large project)


GlueGunner4
27 Apr 2020, 14:37

I think I edited the core command correctly, but when I tried to do the second part:

Error running script: Error evaluating expression 'GetBoolean(object, "hidechildren")': GetBoolean 
function expected object parameter but was passed 'null'

I got that error.
Does the container go in the exit or in the overall room? I think that might be where I'm Messing up.


mrangel
27 Apr 2020, 18:05

That error looks like the exit doesn't have a destination. In order for that script to work correctly, you probably need to set the exit's destination to the container with the objects inside.

Does the container go in the exit or in the overall room?

I assumed the exit was pointing to a room which contains the objects. If you have the objects inside the exit itself, then change this.to in the script to this. Then you don't need the containers; you can just give the exit an attribute isopen with the value true. I didn't suggest that originally because I don't know if the desktop editor will allow you to put objects inside an exit (if it does, it should work well).


GlueGunner4
28 Apr 2020, 15:22

Thanks for the help.
Yes, I'm trying to put the objects in the exit.
So I changed the script to this, and made the isopen attribute true. I started the game, typed
Look West
And the game crashed. I tried again, with the same results. Strange, I don't know what I'm doing wrong.
I'm trying to post the game code, but it formats everything weird. Something with the < and >.😕


GlueGunner4
28 Apr 2020, 16:09

Wait a minute! I did it! That script worked! All I had to do was not use any look-only exits and put that script in the "run a script instead of moving the player." The only problem is that the objects stay in view when you turn away. How could I fix that?


mrangel
28 Apr 2020, 17:37

Hmm… you might be able to hide the objects by adding something like:

foreach (exit, ScopeExits()) {
  exit.hidechildren = true
}

So that when you look in one direction, it hides the others first.

But in that case, I think it might have been easier to make several "rooms" representing different parts of the room, with regular exits between them.