How to handle complex / sub-objects?
Woodhouse3D
11 Nov 2024, 12:45How would you handle complex / sub-objects? I mean, something like a NPC having a face or other body parts. The player could then use a command like "Shave John's face" or "shoot Jake in chest". Or maybe like a puzzle box with multiple disks and knobs.
(This is a QuestJS question but I imagine the answer may be similar to that in Quest5.)
daeun
15 Nov 2024, 17:44- create object
john
- go to verbs tab of
john
, addshave
verb, at assignment column, switch torequire another object
- add
face
object inside the assignment column, then add in script
msg ("clean shaven<br/>")
- create object
face
, drag it and put it inside of john - at
john
, go to features tab, tickcontainer
, go to container tab, choosecontainer
, tick hide children until looked at - at
john
, go to object tab, deleteopen
andclose
from display and inventory verbs - play test the game, if you type in "shave john", it is not possible
if you type in "shave john face", it is not possible
if you type in "look john", "shave john", it would list out a possible list of options, when you click on1. face
,
you will finally shave john's face, receiving a confirmation message "clean shaven" - additionally, if you feel like hiding the sub-objects afterwards, go to
john
, setup tab, atlook at
, switch to run script and add this
SetTimeout (9) {
MakeObjectInvisible (face)
}
Quick demo/ Sample code
To paste the code
Startup your quest gamebook/textadventure, on the right side of the big play button, you can see a code view button
Copy my code to replace the code in the text box, click code view button again.
Viola, it is done, press play button to test out the game and modify the code to your preference.
<!--Saved by Quest 5.8.6836.13983-->
<asl version="580">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="test15">
<gameid>cb2655e4-6bfc-4dd5-be83-b7cab36b49af</gameid>
<version>1.0</version>
<firstpublished>2024</firstpublished>
</game>
<object name="room">
<inherit name="editor_room" />
<isroom />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<object name="john">
<inherit name="editor_object" />
<inherit name="container_open" />
<shave type="scriptdictionary">
<item key="face"><![CDATA[
msg ("clean shaven<br/>")
]]></item>
</shave>
<feature_container />
<hidechildren />
<displayverbs type="stringlist">
<value>Look at</value>
<value>Take</value>
</displayverbs>
<inventoryverbs type="stringlist">
<value>Look at</value>
<value>Use</value>
<value>Drop</value>
</inventoryverbs>
<onopen type="script">
</onopen>
<look type="script">
SetTimeout (9) {
MakeObjectInvisible (face)
}
</look>
<object name="face">
<inherit name="editor_object" />
</object>
</object>
</object>
<verb>
<property>shave</property>
<pattern>shave</pattern>
<defaultexpression>"You can't shave " + object.article + "."</defaultexpression>
</verb>
</asl>
Woodhouse3D
22 Nov 2024, 15:52Very interesting, thank you.
Unfortunately I've decided to refactor the code to use QuestJS' respond() function, and potentially remove these sub-objects entirely, replacing them with dictionaries. For posterity, I will add that QuestJS has built in support for component objects with the COMPONENT() object type.