How to check if an object exists in a room?

writtenhigh
07 Jan 2016, 18:02
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
07 Jan 2016, 19:15
(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
07 Jan 2016, 20:47
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
07 Jan 2016, 20:57
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
07 Jan 2016, 21:20
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
07 Jan 2016, 21:23
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
07 Jan 2016, 21:25
If you want to see if an object exists, then you'd do something like:

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

writtenhigh
07 Jan 2016, 21:35
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!