Beginner needs help with object-presence conditional commands (Solved)
YiKwang
20 Feb 2022, 07:50Hello, I have a question about either Scope, or If conditions, depending on how it is easiest to implement:
I would like to have 2 Commands - 'Light' and 'Sleep'
The Light command is simple:
-Only allow the Player to Light #object# (switch on object) if the Player's Inventory contains an Object with the Attribute 'ISaIGNITER', and if the target object has Attribute 'ISaBURNER'
I would like the Sleep Command to have 2 outputs, making it a little trickier:
- If the player is in a room which contains a reachable object with the Attribute 'ISaBED' - the output will be 'You sleep comfortably' with say, 3 HP gained.
- If the player is in any room that does not contain an Object with Attribute 'ISaBED', I want output 'You sleep poorly' and a gain of only say, 1 HP.
Note: I may want the possibility of an inventory object which also has 'ISaBED' (bedroll, etc) - which probably wont need to be dropped or anything, just present in inventory.
I hope that is not too sloppily described, any help would be much appreciated, this is my first time using Quest or making any kind of Text Adventure!

YiKwang
20 Feb 2022, 09:11I'm realising that what I really wish is that there were IF options such as:
- Reachable has Attribute
- Visible has Attribute
- Inventory contains Attribute
mrangel
20 Feb 2022, 10:45
- Reachable has Attribute
- Visible has Attribute
- Inventory contains Attribute
You can write all of these expressions using the functions FilterByAttribute
and FilterByNotAttribute
.
The various Scope commands mostly return a list of objects. You can then use the Filter commands to filter this list of objects down to the ones you want; and ListCount
to check if there are any objects in the list.
ScopeReachableInventory()
gives all the reachable objects in your inventoryFilterByAttribute (ScopeReachableInventory(), "ISaIGNITER", true)
gives all objects in the inventory whose ISaIGNITER attribute has the valuetrue
ListCount (FilterByAttribute (ScopeReachableInventory(), "ISaIGNITER", true))
gives the number of itemsListCount (FilterByAttribute (ScopeReachableInventory(), "ISaIGNITER", true)) > 0
givestrue
if the player has one
So your "light #object#" script might look like:
if (not GetBoolean (object, "ISaBURNER")) {
msg ("That's not something you can light.")
}
else if (ListCount (FilterByAttribute (ScopeReachableInventory(), "ISaIGNITER", true)) = 0) {
msg ("You don't have anything to light it with.")
}
else {
// code to light it goes here
}
Note that this is assuming those attributes will have the value true
. If you want to just test that the attribute exists, then you would check if it matches the special "no such attribute" value, null
. Like this:
if (not HasAttribute (object, "ISaBURNER")) {
msg ("That's not something you can light.")
}
else if (ListCount (FilterByNotAttribute (ScopeReachableInventory(), "ISaIGNITER", null)) = 0) {
msg ("You don't have anything to light it with.")
}
else {
// code to light it goes here
}
And your sleep command should also be pretty simple:
if (ListCount (FilterByNotAttribute (ScopeReachable(), "ISaBED", null)) > 0) {
msg ("You sleep comfortably.")
// increase HP by 3
}
else {
msg ("You sleep poorly.")
// increase HP by 1
}
(I used ScopeReachable
here; which includes objects both in the room and in the inventory. If you don't want to allow a bed in the inventory, you could use ScopeReachableNotHeld
instead)

YiKwang
20 Feb 2022, 11:47So, I have put in an IF (via GUI, not Code) which looks like:
IF: [ expression ] [ listcount (filterbyattribute (scopereachable(), "ISaBED", true)) > 0 ]
^Then:
Print [ message ] etcetcetcetc
etcetcetc
But when I use the Sleep command, I get the error:
sleep
Error running script: Error compiling expression 'listcount (filterbyattribute (scopereachable "ISaBED", true)) > 0': Unknown object or variable 'scopereachable'
If I swap the scopereachable and filterbyattribute in the expression above, it gives the same error but with:
Unknown object or variable 'filterbyattribute'
which makes it look like a problem with syntax or something... any ideas?

YiKwang
20 Feb 2022, 11:53I redid the command using your filterbynotattribute method as you exampled above, and it works fine, but im still curious why the opposing version didn't work if you can tell me.
mrangel
20 Feb 2022, 12:54I redid the command using your filterbynotattribute method as you exampled above, and it works fine, but im still curious why the opposing version didn't work if you can tell me.
In the error message you quote, there are several errors. Firstly, the capital letters (scopereachable
is not the same as ScopeReachable
). And secondly, the parentheses. scopereachable
would be interpreted as the name of an object or variable (hence the "unknown object or variable" message), while ScopeReachable()
is a function.

YiKwang
20 Feb 2022, 13:18I'm now having trouble with the Switch On Else result.
I thought I could just put
[Switch On] [Expression] object
to have the game switch on the #object# from the original command.
How do I refer to the #object# given in the player command?

YiKwang
20 Feb 2022, 13:42Sorry, I was being super nooby, I figured it out!