How do I do OR?
ScruffyMusk
07 Nov 2016, 21:59I have scenes that I want to play if the character has certain attributes.
How do I make it so a scene will play if a player has attribute = x OR attribute_two = y ?
I know in Java it would use || but that doesn't seem to work here. Thanks for the help!
hegemonkhan
07 Nov 2016, 23:30quest is user-friendly, so literally:
AND: and
OR: or
Negation (NOT) A: not NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = VALUE_OR_EXPRESSION
~ OR ~
Negation (NOT) B: <> // if you code this in directly (non - GUI/Editor), you need to enclose your scripting within this: '<![CDATA[ /* scripting */ ]]>', to tell quest that your '>' and '<' symbols are 'greater than and 'lesser than' symbols and not as asxl/xml 'creation' tag block symbols, otherwise, the GUI/Editor handles it for you.
examples:
if (player.strength = 100 and player.endurance = 100) { /* scripts */ } // and
if (player.strength = 100 or player.endurance = 100) { /* scripts */ } // or
// Negation (Not):
if (player.strength <> player.endurance) { /* scripts */ }
// or
if (not player.strength = player.endurance) { /* scripts */ }
// ----------------
<function name="example">
<![CDATA[[
if (test.score >= 90) {
test.grade = "A"
} else if (test.score >= 80) {
test.grade = "B"
} else if (test.score >= 70) {
test.grade = "C"
} else if (test.score >= 60) {
test.grade = "D"
} else {
test.grade = "F"
}
]]>
</function>
// or
<function name="example"><![CDATA[[
if (test.score >= 90) {
test.grade = "A"
} else if (test.score >= 80) {
test.grade = "B"
} else if (test.score >= 70) {
test.grade = "C"
} else if (test.score >= 60) {
test.grade = "D"
} else {
test.grade = "F"
}
]]></function>
// -----------------------------
<function name="example2">
<![CDATA[[
if (player.strength <> 100) {
msg ("The player's strength is not equal to 100")
}
]]>
</function>
// or
<function name="example2"><![CDATA[[
if (player.strength <> 100) {
msg ("The player's strength is not equal to 100")
}
]]></function>
see this link for a guide on quest's syntax, and Attributes and the 'if' Script usage:
http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk
(this was back when I was still learning coding, so ignore me saying the boolean logical operators are bit operators)
(I don't think quest has the 'XOR' boolean logic operator)
quest's doc:
http://docs.textadventures.co.uk/quest/
ScruffyMusk
08 Nov 2016, 00:21Wow I can't believe it's literally or. I feel real silly now haha, thanks!