Trying out the ScopeVisible() command
Brian5757
29 Feb 2020, 10:54In the help part of Quest I'm told that the ScopeVisible() command returns an objectlist of the objects that the player can see.
I'm trying to display the objectlist but no luck so far.
I tried this code:
ll = NewObjectList()
ScopeVisible()
msg (ListCount(ll))
msg(ObjectList)
mrangel
29 Feb 2020, 13:57Let's look at the code line by line:
ll = NewObjectList()
- calls the (built-in) function "NewObjectList", which creates a new objectlist and returns it. The returned (empty) objectlist is stored in a local variable namedll
ScopeVisible()
- calls the (core) function "ScopeVisible", which returns an objectlist of visible objects. There's no=
, so we don't do anything with this list.msg (ListCount(ll))
- calls the (built-in) function "ListCount", which returns the number of elements in the listll
(currently zero, asll
is the empty list returned by NewObjectList(). The returned number (0) is passed to the built-in statement "msg", and printed outmsg(ObjectList)
- calls the built-in statement "msg", to print out the contents of a local variable namedObjectList
. If you haven't already created this variable, you will get an error.
I think what you probably meant is:
ll = ScopeVisible()
msg (ListCount(ll))
msg (FormatList (ll, ", ", ", and", "nothing"))
(In this case, I added the (core) function FormatList
, which turns an objectlist into a human-readable string that looks like "my parents, an elephant, and Joe Stalin".
The parameters to this function are:
ll
- the list to display", "
- the string which should be used to separate items in the list", and"
- the string which should be placed between the last two list elements"nothing"
- what to display if the list is empty
Brian5757
01 Mar 2020, 01:13Thanks mrangel. That works well.
I don't understand why there is a command "ScopeReachableForRoom(room) as the player is only able to reach for objects in the current room and no other room, unless you devide the current room into two parts EastLounge and WestLounge; but then how do you tell Quest that while in the WestLounge you are able to reach for objects in the EastLounge?
mrangel
01 Mar 2020, 09:15I don't understand why there is a command "ScopeReachableForRoom(room) as the player is only able to reach for objects in the current room
It finds objects that would be reachable if the player were in a specific room. In most cases you won't need to use it. The most obvious use I can think of is when you're writing scripts to have an NPC move around the map and do things (either automatically, or with the player telling them what to do). You'd use an expression like ScopeReachableForRoom (npc.parent)
to find out what objects the NPC can reach.
Brian5757
01 Mar 2020, 11:16Useful to know thanks mrangel