Trying to find text in a game for Cloak of Darkness example
Brian5757
03 Jan 2020, 11:22I'm studying the 'cloak of darkness.asxl' game.
If I type 'listen' while being in any room other than the cloakroom room I get a message "You can hear the rain pouring against the windows". if I type 'listen' while I'm in the cloakroom I get the message "It is quiet as a grave"
I can't find anywhere in the quest program the text "You can hear the rain pouring against the windows" in the interface type programming, but I can see it in the 'code view'. Is this text something that has to be added in the code view and is unable to be added to the interface type programming (drop down menus, tick boxes, etc)?
The command that activates it is 'print expression player.parent.listen'
mrangel
03 Jan 2020, 12:17listen
is a custom attribute that only exists in that game, so there isn't a space for it in the GUI.
If you have the desktop version of Quest, you can go to the "Attributes" tab of an object to see all the attributes that are currently defined. It just gives a list of attribute names and their initial values, and you can add new attributes as you wish.
The expression you've found, player.parent.listen
is a good example of using object references.
player
is the object whose name is "player". It's an object, so you can follow it with a dot to access any of its attributes.player.parent
is a special attribute referring to the room the player is inside. The room is also an object, so you can add another dot to access its attributes.player.parent.listen
is thelisten
attribute of the current room.
The string "You can hear the rain pouring against the windows." is the initial value of foyer.listen
, while "It is quiet as the grave..." is the default displayed in a room that doesn't have a listen
attribute.
Brian5757
03 Jan 2020, 12:28Thanks mrangel.
Looks like there is lots to learn but it will be worth it.
mrangel
03 Jan 2020, 17:48One thing: I wouldn't advise using player
in code. It's not a problem here, but is a bad habit. Because if someone else is using your code as a reference, their player object might not be named player
, which leads to the same problems being posted on the forums every month or so.
It would be more robust to use pov
, an attribute of the game
element which is a reference to the current player object. (You can set this attribute at the top of the game's "Player" tab).
So instead of player.parent.listen
, it might be better to put game.pov.parent.listen
; so that the code will continue working even if it's reused in a game where the player can switch between controlling different characters.