Move to object

Can somebody help a non coder. I want to allow the player to move magically to a room containing an object (box) which could be anywhere. I did this once before in a previous game I never published giving the object (box)as the target location. This mysteriously changed to FilterByAttribute ListParents (box), “isroom”, true). Player also changed to game.pov ( I know that one)
I am fundamentally rewriting this game.
An error message insists that column 61 is incorrect. Is that the second comma? Are spaces critical?
Location called box moves you to the box . I want the player standing beside it.
I try my best but am in my late 70s . I just can’t muster enough grey cells for coding.


I think most people would use the expression box.parent - which refers to the room or object containing box. That will work as long as the box isn't inside another box.

FilterByAttribute (ListParents (box), “isroom”, true)) is a slightly more robust expression. It goes through all the objects that box is inside, and gets a list of all the ones that are rooms. However, that's a list of rooms, not a room, so I suspect that it won't work if you pass it to MoveObject.

I think that you could probably use something like ListItem (FilterByAttribute (ListParents (box), “isroom”, true)), 0) to get the first object on that list, which will be the outermost room the box is in.

If there's a possibility that the box is inside a room inside a room and you want to move the player to the inner one, you'd want a slightly more complex script. This goes over the objects the box is inside, closest first, until it finds one that is a room.

room = box
while (not GetBoolean (room, "isroom") and HasObject (room, "parent")) {
  room = room.parent
}
MoveObject (gamme.pov, room)

Hope that's clear enough. Alternatively, you could just use the expression box.parent - as long as you're sure the box won't be inside a non-room container.


Hope that all makes sense. And for future reference, the character counting for error messages is a bit wonky. In order to say what's wrong with a particular line of code, it will help a lot if you can quote the actual error. You can put it code and error messages between a pair of backticks (`) so that the forum doesn't try to add weird formatting.

Many thanks mrangel . That worked fine.


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

Support

Forums