Operation 'And' is not defined for types 'Element' and 'Element'?
Yellow_Anonymous
26 Jun 2018, 14:35I'm trying to set up a script for an exit that checks to see if the player is carrying two specific objects, then displaying a wall of exposition before letting them leave. The problem is that apparently the "and" operation isn't defined to find out if the player has two specific objects. I've tried using the "and" operation to detect if the player is carrying the objects in their inventory and using the operation to detect if both items have the "carried" object flag, a flag only set if the player picks up the objects. But both methods return an error message stating that the "and" operation isn't defined for types "Element" and "Element".
Here's the coding setup I have.
if (GetBoolean(photograph and map, "carried")) {
firsttime {
ClearScreen
PrintCentered (Yadda yadda yadda yadda)
}
}
Am I using the wrong operation entirely? Am I just using the "and" operation wrong?
hegemonkhan
26 Jun 2018, 14:49no, just the wrong syntax, each condition must be a statement, and it's 'GetBoolean (NAME_OF_OBJECT, "NAME_OF_BOOLEAN_ATTRIBUTE"):
if (CONDITION_STATEMENT_1 and CONDITION_STATEMENT_2) {
// whatever scripting
}
// ------
CONDITION_STATEMENT_1: GetBoolean (photograph, "carried") ---> (true/false)
CONDITION_STATEMENT_2: GetBoolean (map, "carried") ---> (true/false)
// -------------------------------
'AND' logic:
true and true ---> TRUE
true and false ---> FALSE
false and true ---> FALSE
false and false ---> FALSE
// ----------------
// these have to be existing Objects, examples via using scripting:
create ("photograph")
create ("map")
// then, continuing the example using scripting, let's set the built-in 'take' Boolean Attribute to 'true' for them, so they can be picked up (put into your inventory):
photograph.take = true
map.take = true
// since I'm not sure if the built-in 'drop' Boolean Attribute is set to 'true', using scripting to create an Object, let's set it to 'true', to be safe, lol:
photograph.drop = true
map.drop = true
// continuing this example, we now need your 'carried' Boolean Attributes to exist as well:
photograph.carried = false
map.carried = false
// continuing this example, we need to have the built-in 'take' Script Attribute, to set their 'carried' Boolean Attribute to 'true' and the built-in 'drop' Script Attribute, to set their 'carried' Boolean Attribute to 'false':
photograph.take => {
photograph.parent = player
photograph.carried = true
}
map.take => {
map.parent = player
map.carried = true
}
photograph.drop => {
photograph.parent = player.parent
photograph.carried = false
}
map.drop => {
map.parent = player.parent
map.carried = false
}
// and lastly, your scripting in correct syntax:
if (GetBoolean (photograph, "carried") and GetBoolean (map, "carried")) {
firsttime {
ClearScreen
PrintCentered (Yadda yadda yadda yadda)
}
// optional (do you get an error if you just have 'firsttime', with no 'otherwise {}', ??? (I'm too lazy to check myself, lol):
otherwise {
// whatever scripting or leave blank (or if no error with not even having the 'otherwise {}', than don't even have it, if you don't want any scripting, instead of having it be blank, lol)
}
}
hegemonkhan
26 Jun 2018, 15:01though, if you just want to check if you got Objects in the inventory (aka: contained within the 'game.pov' --- this stores a pointer-reference of/to the Player Object that you're currently controlling, the default is the 'player' Player Object), use this:
https://docs.textadventures.co.uk/quest/functions/corelibrary/got.html
if (Got (photograph) and Got (map)) {
}
there's also:
https://docs.textadventures.co.uk/quest/functions/contains.html
if (Contains (player, photograph) and Contains (player, map)) {
}
there's also:
https://docs.textadventures.co.uk/quest/functions/listcontains.html
https://docs.textadventures.co.uk/quest/functions/#scope
if (ListContains (ScopeInventory (), photograph) and ListContains (ScopeInventory (), map)) {
}
Yellow_Anonymous
26 Jun 2018, 15:16Ah, thank you! Using "Got" worked perfectly!