How to check if an object exists in a room?

writtenhigh
Well, it seemed to me like "contains" would be the appropriate way to check and see if an object exists inside a room, but instead of returning false, it returns

Error running script: Error compiling expression 'contains(blackberry_manor,blackberries)': Unknown object or variable 'blackberries'


How do I check for an object, then?

OurJud
(I) Don't use the designated functions for stuff like this. I find them confusing and erratic.

(I) Just use a series of custom commands and if scripts.

writtenhigh
I tried using if statements, but couldn't figure out how to reference the specific object.

if (blackberries){}?
if (game.blackberries){}?
if (blackberry_manor.blackberries){}?

Ultimately, I want to be able to determine if the object exists either in the current room or in the players inventory. And I need it to return false if it doesn't, instead of throwing an error. o_0

jaynabonne
if (blackberries.parent = blackberry_manor)
...

Current room or player's inventory (we'll use blackberries again):

if (blackberries.parent = player or blackberries.parent = player.parent)
...

writtenhigh
Still doesn't return false.

Error running script: Error compiling expression 'blackberries.parent = blackberry_manor': Unknown object or variable 'blackberries'



When running

<script>
if (blackberries.parent = blackberry_manor) {
msg ("You've already eaten enough blackberries.")
}
</script>


When the blackberries are not in the room.

jaynabonne
Then that means you don't have an object named blackberries. Can you give more context about what you're trying to do? Do you have an object named "blackberries"? If not, then it makes no sense to try to reference it!

It shouldn't matter if the object is in the room, but the object has to exist.

jaynabonne
If you want to see if an object exists, then you'd do something like:

if (not GetObject("blackberries") = null)
...

writtenhigh
Sorry! My bad!

I needed to know both pieces of information (whether the blackberries existed at all, and whether they existed in a specific room and/or the players inventory.) GetObject() was the piece of the puzzle I was missing.

Thanks!

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

Support

Forums