Can a surface tell you when it's empty?

Anj Avraam
09 Feb 2014, 19:14
Hi, I've been experimenting with various methods for doing this and I'm stuck. All I seem to do is create weird and wonderful errors.

I have created a bed which is a 'surface' and on it is a pillow, a quilt and a sheet.

I want the game to know when the bed is empty, and give the player the message, "The bed has been stripped."

In all there could potentially be three states the bed can be in:
1) Untouched (i.e. all objects in their original positions) = "made"
2) Things moved (i.e. anything has been taken or put/the original state is different but it still has objects on it) = "unmade"
3) Stripped (i.e. no objects on the bed except the container/surface/scenery part of the bed) = "stripped"

And ideally I'd have messages for these different states. I've tried using flags, using 'if', using scripts in the container description, and I've scoured the forum to see if this is already dealt with but haven't found my answer yet. If anyone could help I would be grateful!

HegemonKhan
09 Feb 2014, 21:27
You're on the right track, just missing (or unaware of) a few extra steps (coding lines) that are needed, hehe.

1. http://quest5.net/wiki/Category:All_Fun ... t_Commands (page 1, range: A-S)
2. http://quest5.net/w/index.php?title=Cat ... h#mw-pages (page 2, range: S-Z)

there's quite a few ways to do this... hmm...

you're dealing with whether an Object "contains or has" other Objects, so you'll need:

1. "if..." Script ( http://quest5.net/wiki/If )

2. "HasObject" Script ( http://quest5.net/wiki/HasObject ) or "Contains" Script ( http://quest5.net/wiki/Contains ) or "ContainsAccessible" Script ( http://quest5.net/wiki/ContainsAccessible ) or "ContainsReachable" Script ( http://quest5.net/wiki/ContainsReachable ) or "ContainsVisible" Script ( http://quest5.net/wiki/ContainsVisible )

3. (optional) 1-3 Boolean Attributes (Booleans are same as Flags) or a "String List" Attribute or an "Object List" Attribute:

Booleans:

"stripped"
"unmade"
"made"

~OR~

String List:

"bed_string_list"
"stripped", "unmade", and "made"

Object List:

(I'm still having trouble with understanding them currently)

4. A "search" (custom) Verb or using a scripted (Run as script) "Look at" (built-in) Verb

-------------------

so for one example:

Object: room
-> Object: bed
->-> Verb: search

"search" Verb:

if (Contains (room.bed, pillow) and Contains (room.bed, quilt) and Contains (room.bed, sheet) = true) {
-> // whatever script
} else if (Contains (room.bed, pillow) or Contains (room.bed, quilt) or Contains (room.bed, sheet) = true) {
-> // whatever script
} else if (Contains (room.bed, pillow) and Contains (room.bed, quilt) and Contains (room.bed, sheet) = false) {
-> // whatever script
}

---------------

err... my bad...

I didn't notice these specifics of yours:

2) Things moved (i.e. anything has been taken or put/the original state is different but it still has objects on it) = "unmade"
3) Stripped (i.e. no objects on the bed except the container/surface/scenery part of the bed) = "stripped"

this stuff is a bit more complicated to implement... hmm...

2) Things moved (i.e. anything has been taken or put/the original state is different but it still has objects on it) = "unmade":

you'll have to work with Object Lists...

http://quest5.net/wiki/Using_Lists
http://quest5.net/wiki/Objectlist
http://quest5.net/wiki/GetAllChildObjects
http://quest5.net/wiki/GetDirectChildren

if (not GetDirectChildren (room.bed) = null and Contains (room.bed, pillow) and Contains (room.bed, quilt) and Contains (room.bed, sheet) = false) {
-> // whatever script
}

3) Stripped (i.e. no objects on the bed except the container/surface/scenery part of the bed) = "stripped":

you'll have to do a "foreach" + "checking" scripting...

foreach (object_x, room.bed) {
-> if (HasBoolean (object_x.scenery) = false) {
->-> if (

... err... this is too complicated for my brain at the moment... maybe later I can think clearly on this...

george
09 Feb 2014, 22:11
I think I would put a state attribute on the bed that was a function. Here's a minimal example:


<!--Saved by Quest 5.4.4873.16527-->
<asl version="540">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="unmade bed">
<gameid>a659c68e-97c1-4d30-9c8d-8c229e1b08e2</gameid>
<version>1.0</version>
<firstpublished>2014</firstpublished>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<object name="bed">
<inherit name="editor_object" />
<state type="script">
myfunc
</state>
<baz type="script">
invoke (this.state)
</baz>
</object>
</object>
<verb>
<property>baz</property>
<pattern>baz</pattern>
<defaultexpression>"You can't baz " + object.article + "."</defaultexpression>
</verb>
<function name="myfunc" type="string">
msg ("Hello it's myfunc")
</function>
</asl>


Your function ('myfunc') would calculate the state of the bed and return the result as strings, either "made", "unmade", or "stripped". When you wanted to print a message to the player concerning the bed, you would invoke(bed.state) and use the result as you like, for example in a switch/case.

http://quest5.net/wiki/Switch

For the situation where the bed is 'unmade', you might want to put an attribute, for example in_place, on each bed item, that's true or false.

Then when you calculate the state of the bed (by looking at it with GetDirectChildren as HK linked to in his post), you can also test if each item is in_place to determine if the bed is made. If an item is not in_place, the bed isn't made.

side note: This is an interesting question, because as I was playing with it I discovered that I couldn't find the source of GetDirectChildren. Normally Quest functions are findable in the desktop editor (with Filter -> Show library elements). The best I could do was finding it in the source here,

http://quest.codeplex.com/SourceControl ... lements.cs

Anj Avraam
10 Feb 2014, 15:02
Thank you both, HegemonKhan and george. Both extremely helpful replies.

I will now work through these options and hopefully will return with news of my success soon!