Showing the player that a new object has come into the current room?

If I type in a command that will cause an object to move to the current room there does not seem to be a script command such as LOOK to show the player the new object in the current room. I suspect the same applies to an invisible object becoming visible.

Brian


"...there does not seem to be a script command such as LOOK to show the player the new object in the current room"

From what I can take from what you said, you want the players to be noticed as soon as the new object arrives. I'm sorry if I misunderstand it >.<

I'm not really a pro at this kind of stuff, but you may consider using a turnscript:

Add script > IF... > If object.parent = player.parent
//Put description (You may want to do it manually with add text script or do sth to trigger the description in the code)

or a change script on the object with similar content. Also, just a footnote, but I use "object" and "player" since I know neither the name (not alias) of your player nor that of your object and not because it is supposed to be written exactly like that.

Hope it helps, though I'm not sure it will


Yeah just after moving object to room just use a print message or you could use an expression then type in

"Standing there a " +object.name+ " appears in front of you!"

this will get the name of the object and display it in message.


Thanks but if I use the
"Standing there a "+object.name+ "appears in front of you"
then how do I use this if two objects have moved into the current room onimike?

Brian


I'm trying to understand what you wrote Y4T5UR0 but don't fully understand what you mean by
//Put description (You may want to do it manually with add text script or do sth to trigger the description in the code)

Brian


You want GetDisplayAlias (object), not object.name.

If you have a script that's moving multiple objects into the player's room, you can just list them manually:

msg ("You hear the sound of the door opening again behind you, and when you turn around you see a {object:bell}, a {object:book}, and a {object:colin} on the floor.")

You can do that as part of the code that moves the objects.


If you're using the changedparent script to generate these messages, then it will display a message for each object that has moved, although that might look a bit weird if there are several objects.

I can see two ways to make "X and Y have entered the room" messages, aside from doing in manually in the script that moves those objects. You could use the roomenter script to store a list of objects in the room, and then have a turnscript that compares this list against the current scope, displaying a list of objects that have entered or left. Or you could have the changedparent script add its message to a queue, and have a turnscript which combines identical messages before displaying them.

I could show you the code for either of those methods; but I think they're overkill for 90% of the likely cases - in most games, objects will only enter the room if a script is moving them, so you can use that script to display the message.


onimike
using a script command to move an object to the current room I found that if I use the expression "Standing there a " +object.name+ " appears in front of you!" I get an error as Quest does not know the object name.

Brian


Thanks mrangel.

I was thinking that a Look command could deal with any random object entering the room.
Does Quest have a script command for entering text just like the player enters text
eg Command(Wash Bottle) or Command(Look).

There is also a clear screen command so maybe that would cause a Look command to be performed to show the romm and its contents and if the script was run in the right order then the moved object would appear.

Brian


Hi mrangel.

In your message to me you spoke of different types of scripts which were "changedparent" script and the "roomenter" script.
I mainly use the users interface screen so I don't know if this can be done from that screen or are these coded in on the code screen. Can you give me an example of one of these scripts please.

Brian


using a script command to move an object to the current room I found that if I use the expression "Standing there a " +object.name+ " appears in front of you!" I get an error as Quest does not know the object name.

If you're using a script command to move an object, you know the name of the object.

For a script that always moves the same object, use the name of the object directly.

For a script that moves different objects around, that script must have a variable holding the object to move. Use the same variable to get the name of the moved object.

But as I said before, you should be using either {object:name_of_object} in a string, or GetDisplayName (variable referring to object) in an expression. An object's name is what Quest refers to it as internally.


Does Quest have a script command for entering text just like the player enters text
eg Command(Wash Bottle) or Command(Look).

Yes, but you don't want to do that.

A few methods. You should know about them in case you want to use them later, but right now you don't need them all.

Method 1. Just do the thing

The script for the "look" command is very simple. It runs a single function.
So to display the room description again, you can call the same function:

ShowRoomDescription()

Method 2. Call the command script directly

If you know the name of a command (which isn't always the same as its pattern), you can call that script using the do command.

do (look, "script")

This will act exactly as if the player had entered the command, but won't run any turnscripts or similar.
If you want to pass parameters to the command, you'd need to add them to a dictionary, like this:

parameters = NewDictionary()
dictionary add (parameters, "exit", exit127)
do (go, "script", parameters)

or

parameters = NewDictionary()
dictionary add (parameters, "object1", bunny)
dictionary add (parameters, "object2", box)
do (go, "script", parameters)

Method 3. Invoke the command parser

HandleSingleCommand ("look")
HandleSingleCommand ("go north")
HandleSingleCommand ("put the bunny in the box")

This is really inefficient, because it has to compare your text to every single command, just like it does when the player types something. This is one of the most processor intensive parts of the Quest engine, so you should try to avoid it unless there's really no other option.

Note also that this will pop up a disambiguation menu if there's more than one visible object with the same name, or give the player an uninformative message if the object isn't visible. Just as if they'd entered the command.
This will also run turnscripts, so if your game is counting turns, it will count all of these commands.

It may also introduce some bugs, because your turnscripts will be running out of order.
If this causes a problem, it's better to do:

if (not HasAttribute (game.pov, "commandqueue")) {
  game.pov.commandqueue = NewStringList()
}
list add (game.pov.commandqueue, "look at bunny")

This will cause the current command to finish, (running all turnscripts as necessary), and then run the command you specify (with all its command scripts).


In your message to me you spoke of different types of scripts which were "changedparent" script and the "roomenter" script.

OK. "roomenter" is a script attached to the game object. I think it's on the 'Scripts' tab of the game.

This is the script that is run every time the player enters a new room.

"changedparent" is a script which is run automatically every time an object's "parent" attribute is changed. I believe in the desktop version of Quest you can change this on an object's 'Attributes' tab.
parent is the room, container, or NPC that an object is currently in; so an object's changedparent script is run every time it is moved.

By default, all objects have a changedparent script which looks like this (English translation):

if (this object is the player) {
  run the new room's enter scripts
  show the room description
  update the map
}

for objects that move around themselves, you could change it to something like (bits I added in bold):

  if (game.pov = this) {
    if (IsDefined("oldvalue")) {
      OnEnterRoom(oldvalue)
    }
    else {
      OnEnterRoom(null)
    }
    if (game.gridmap) {
      MergePOVCoordinates
    }
  }
  else if (this.parent = game.pov.parent) {
    msg (CapFirst (GetDisplayName (this)) + " has entered the room.")
  }
  else if (IsDefined ("oldvalue")) {
    if (oldvalue = game.pov.parent) {
      msg (CapFirst (GetDisplayName (this)) + " has left the room.")
    }
  }
  this.hasbeenmoved = true

Thanks mrangel.
I'll do some experimenting on what you have taught me.

Brian


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

Support

Forums