Cannot use conditional operators in switch keys?
xordevoreaux
22 Apr 2016, 15:55I've a switch set up to avoid a bunch of If statements.
The expressions for two keys are just direct references to variables and they work.
The other two are conditional statements:
>game.wt_worldclock_lighttime and <game.wt_worldclock_darktime
>game.wt_worldclock_darktime and <game.wt_worldclock_lighttime
Error running script: Error compiling expression '>game.wt_worldclock_lighttime and <game.wt_worldclock_darktime': SyntaxError: Unexpected token ">"; expected one of "NOT", "-", <INTEGER>, <REAL>, <STRING_LITERAL>, "True", "False", <HEX_LITERAL>, <CHAR_LITERAL>, "null", <DATETIME>, <TIMESPAN>, "(", <IDENTIFIER>, "if", or "cast"Line: 1, Column: 1
The expressions for two keys are just direct references to variables and they work.
The other two are conditional statements:
>game.wt_worldclock_lighttime and <game.wt_worldclock_darktime
>game.wt_worldclock_darktime and <game.wt_worldclock_lighttime
Error running script: Error compiling expression '>game.wt_worldclock_lighttime and <game.wt_worldclock_darktime': SyntaxError: Unexpected token ">"; expected one of "NOT", "-", <INTEGER>, <REAL>, <STRING_LITERAL>, "True", "False", <HEX_LITERAL>, <CHAR_LITERAL>, "null", <DATETIME>, <TIMESPAN>, "(", <IDENTIFIER>, "if", or "cast"Line: 1, Column: 1
xordevoreaux
22 Apr 2016, 16:12I gave up and converted them all to If statements.
HegemonKhan
22 Apr 2016, 16:40assuming those are Boolean Attributes...
you can't have the angle symbols, that's what's causing the error.
so change it to these:
-------------
Truth (Boolean logic) Tables:
https://en.wikipedia.org/wiki/Truth_table
https://en.wikipedia.org/wiki/Logic_gate (this is at the circuitry level, computer/electronics/electricity engineer/physics science type of stuff)
Quest's 'and' Operator:
true and true -> TRUE
false and true -> FALSE
true and false -> FALSE
false and false -> FALSE
example:
quest's 'or' operator:
true or true -> TRUE
false or true -> TRUE
true or false -> TRUE
false or false -> FALSE
quest's 'not' or 'not =' or '<>' (not / not-equals, aka: negation: opposite) operators:
not (true) -> FALSE
not (false) -> TRUE
quest's syntax examples:
if (not player.alias = "HK") { /* scripts */ }
if (not player.alias = "john") { /* scripts */ }
if (not orc.dead) { /* scripts */ }
if (not player.flying) { /* scripts */ }
<![CDATA[ if (player.alias <> "HK") { /* scripts */ ]]>
<![CDATA[ if (player.alias <> "john") { /* scripts */ ]]>
I don't think quest has the 'xor (exclusive or)' operator, but here's it's truth table:
true or true -> FALSE
false or true -> TRUE
true or false -> TRUE
false or false -> FALSE
same with these other boolean logic operators, I don't think quest has them:
NAND (not and):
(it's just the opposite, aka 'negation: not', results of 'and' )
true and true -> FALSE
false and true -> TRUE
true and false -> TRUE
false and false -> TRUE
NOR (not or):
(it's just the opposite, aka 'negation: not', results of 'or' )
true or true -> FALSE
false or true -> FALSE
true or false -> FALSE
false or false -> TRUE
XNOR (not exclusive or):
(it's just the opposite, aka 'negation: not', results of 'xor' )
true or true -> TRUE
false or true -> FALSE
true or false -> FALSE
false or false -> TRUE
DeMorgan's Laws:
https://en.wikipedia.org/wiki/De_Morgan%27s_laws
-----------------------------------------
I don't know if you can do this as using the 'switch' Script/Function...
but it'd look like this... I think... if it can be done (though I'm pretty sure you can't do this...):
as I think it will work like this instead...:
which, if you understand programming, means that you'd never be able to get the outputs of 'Sorry, you're just not as cool as HK.' and nor of 'You're not even a real person, let alone being the awesome HK.'
so, to be sure of what would work, you'd need to do nested 'switch' Script/Functions, either using (not sure on which, if if both, works):
or
-----------
using 'if' Scripts is actually more clean than 'switch', as well has having full utility (whereas 'switch' may not), and they both otherwise do the exact same thing. But, if you can use 'switch', it can be easier to understand and/or more clean for people.
--------------------------
again, I'm not sure if can and/or how it's done with the 'switch' Script/Function, but here's how the 'greater than' and etc stuff works with the 'if' Scripts, an example:
you can't have the angle symbols, that's what's causing the error.
so change it to these:
game.wt_worldclock_lighttime and game.wt_worldclock_darktime
game.wt_worldclock_darktime and game.wt_worldclock_lighttime
-------------
Truth (Boolean logic) Tables:
https://en.wikipedia.org/wiki/Truth_table
https://en.wikipedia.org/wiki/Logic_gate (this is at the circuitry level, computer/electronics/electricity engineer/physics science type of stuff)
Quest's 'and' Operator:
true and true -> TRUE
false and true -> FALSE
true and false -> FALSE
false and false -> FALSE
example:
// situation 1:
player.alias = "HK"
player.is_real_person = true
// output: HK is awesome in real life!
// situation 2:
player.alias = "HK"
player.is_real_person = false
// What?!... I am TOO a real person!!!!!
// situation 3:
player.alias = "john"
player.is_real_person = true
// Sorry, you're just not as cool as HK.
// situation 4:
player.alias = "john"
player.is_real_person = false
// You're not even a real person, let alone being the awesome HK.
// 'If' Scripting:
if (player.alias = "HK" and player.is_real_person) {
msg (player.alias + " is awesome in real life!")
} else if (player.alias = "HK" and not player.is_real_person) {
msg ("What?!... I am TOO a real person!!!!!)
} else if (not player.alias = "HK" and player.is_real_person) {
msg ("Sorry, you're just not as cool as HK.")
} else if (not player.alias = "HK" and not player.is_real_person) {
msg ("You're not even a real person, let alone being the awesome HK.")
}
quest's 'or' operator:
true or true -> TRUE
false or true -> TRUE
true or false -> TRUE
false or false -> FALSE
quest's 'not' or 'not =' or '<>' (not / not-equals, aka: negation: opposite) operators:
not (true) -> FALSE
not (false) -> TRUE
quest's syntax examples:
if (not player.alias = "HK") { /* scripts */ }
if (not player.alias = "john") { /* scripts */ }
if (not orc.dead) { /* scripts */ }
if (not player.flying) { /* scripts */ }
<![CDATA[ if (player.alias <> "HK") { /* scripts */ ]]>
<![CDATA[ if (player.alias <> "john") { /* scripts */ ]]>
I don't think quest has the 'xor (exclusive or)' operator, but here's it's truth table:
true or true -> FALSE
false or true -> TRUE
true or false -> TRUE
false or false -> FALSE
same with these other boolean logic operators, I don't think quest has them:
NAND (not and):
(it's just the opposite, aka 'negation: not', results of 'and' )
true and true -> FALSE
false and true -> TRUE
true and false -> TRUE
false and false -> TRUE
NOR (not or):
(it's just the opposite, aka 'negation: not', results of 'or' )
true or true -> FALSE
false or true -> FALSE
true or false -> FALSE
false or false -> TRUE
XNOR (not exclusive or):
(it's just the opposite, aka 'negation: not', results of 'xor' )
true or true -> TRUE
false or true -> FALSE
true or false -> FALSE
false or false -> TRUE
DeMorgan's Laws:
https://en.wikipedia.org/wiki/De_Morgan%27s_laws
-----------------------------------------
I don't know if you can do this as using the 'switch' Script/Function...
but it'd look like this... I think... if it can be done (though I'm pretty sure you can't do this...):
switch (player.alias and player.is_real_person) {
case (true and true) {
msg (player.alias + " is awesome in real life!")
}
case (true and false) {
msg ("What?!... I am TOO a real person!!!!!)
}
case (false and true) {
msg ("Sorry, you're just not as cool as HK.")
}
case (false and false) {
msg ("You're not even a real person, let alone being the awesome HK.")
}
}
as I think it will work like this instead...:
switch (player.alias and player.is_real_person) {
case (true) {
msg (player.alias + " is awesome in real life!")
}
case (false) {
msg ("What?!... I am TOO a real person!!!!!)
}
case (false) {
msg ("Sorry, you're just not as cool as HK.")
}
case (false) {
msg ("You're not even a real person, let alone being the awesome HK.")
}
}
which, if you understand programming, means that you'd never be able to get the outputs of 'Sorry, you're just not as cool as HK.' and nor of 'You're not even a real person, let alone being the awesome HK.'
so, to be sure of what would work, you'd need to do nested 'switch' Script/Functions, either using (not sure on which, if if both, works):
switch (player.alias) {
case ("HK") {
switch (player.is_real_person) {
case (true) {
msg (player.alias + " is awesome in real life!")
}
case (false) {
msg ("What?!... I am TOO a real person!!!!!)
}
}
}
case (not "HK") {
switch (player.is_real_person) {
case (true) {
msg ("Sorry, you're just not as cool as HK.")
}
case (false) {
msg ("You're not even a real person, let alone being the awesome HK.")
}
}
}
}
or
switch (player.alias = "HK") {
case (true) {
switch (player.is_real_person) {
case (true) {
msg (player.alias + " is awesome in real life!")
}
case (false) {
msg ("What?!... I am TOO a real person!!!!!)
}
}
}
case (false) {
switch (player.is_real_person) {
case (true) {
msg ("Sorry, you're just not as cool as HK.")
}
case (false) {
msg ("You're not even a real person, let alone being the awesome HK.")
}
}
}
}
-----------
using 'if' Scripts is actually more clean than 'switch', as well has having full utility (whereas 'switch' may not), and they both otherwise do the exact same thing. But, if you can use 'switch', it can be easier to understand and/or more clean for people.
--------------------------
again, I'm not sure if can and/or how it's done with the 'switch' Script/Function, but here's how the 'greater than' and etc stuff works with the 'if' Scripts, an example:
if (student.score >= 90) {
student.grade = "A"
} else if (student.score >= 80) {
student.grade = "B"
} else if (student.score >= 70) {
student.grade = "C"
} else if (student.score >= 60) {
student.grade = "D"
} else {
student.grade = "F"
}
The Pixie
22 Apr 2016, 17:46You can do:
But yes, you might as well do if/else.
switch (true) {
case (time > game.wt_worldclock_lighttime and time < game.wt_worldclock_darktime) {
msg("Stuff")
}
// etc.
}
But yes, you might as well do if/else.
HegemonKhan
22 Apr 2016, 17:51oh, so you do the resulting condition in the 'switch' and the test condition in 'case', never would have realized that, laughs.
Thanks Pixie for the correct response in how quest's switch works.
Thanks Pixie for the correct response in how quest's switch works.
xordevoreaux
22 Apr 2016, 19:43Thanks Pixie for the reply. I'm getting close but it's hanging up on the = sign. Maybe I'll just have to fiddle with it some I don't know.
switch (true) {
case ((game.wt_worldclock_hour=game.wt_wordclock_lighttime)) {
envList = obj.AmbienceMorning
}
case ((game.wt_worldclock_hour=game.wt_worldclock_darktime)) {
envList = obj.AmbienceEvening
}
case ((game.wt_worldclock_hour > game.wt_worldclock_lighttime) and (game.wt_worldclock_hour < game.wt_worldclock_darktime)) {
envList = obj.AmbienceDay
}
case ((game.wt_worldclock_hour > game.wt_worldclock_darktime) and (game.wt_worldclock_hour < game.wt_worldclock_lighttime)) {
envList = obj.AmbienceNight
}
switch (true) {
case ((game.wt_worldclock_hour=game.wt_wordclock_lighttime)) {
envList = obj.AmbienceMorning
}
case ((game.wt_worldclock_hour=game.wt_worldclock_darktime)) {
envList = obj.AmbienceEvening
}
case ((game.wt_worldclock_hour > game.wt_worldclock_lighttime) and (game.wt_worldclock_hour < game.wt_worldclock_darktime)) {
envList = obj.AmbienceDay
}
case ((game.wt_worldclock_hour > game.wt_worldclock_darktime) and (game.wt_worldclock_hour < game.wt_worldclock_lighttime)) {
envList = obj.AmbienceNight
}
HegemonKhan
22 Apr 2016, 20:00quick typo noticed (may still have other issues too) that needs to be fixed:
case ((game.wt_worldclock_hour=game.wt_wordclock_lighttime)) {
you're missing the 'L' there
------
also, this (depending on what you got your Attributes' Values/clock-times-numbers set to being):
case ((game.wt_worldclock_hour > game.wt_worldclock_darktime) and (game.wt_worldclock_hour < game.wt_worldclock_lighttime)) {
envList = obj.AmbienceNight
}
may have to use 'or' instead of 'and', see below:
case ((game.wt_worldclock_hour > game.wt_worldclock_darktime) or (game.wt_worldclock_hour < game.wt_worldclock_lighttime)) {
envList = obj.AmbienceNight
case ((game.wt_worldclock_hour=game.wt_wordclock_lighttime)) {
you're missing the 'L' there
------
also, this (depending on what you got your Attributes' Values/clock-times-numbers set to being):
case ((game.wt_worldclock_hour > game.wt_worldclock_darktime) and (game.wt_worldclock_hour < game.wt_worldclock_lighttime)) {
envList = obj.AmbienceNight
}
may have to use 'or' instead of 'and', see below:
case ((game.wt_worldclock_hour > game.wt_worldclock_darktime) or (game.wt_worldclock_hour < game.wt_worldclock_lighttime)) {
envList = obj.AmbienceNight
xordevoreaux
22 Apr 2016, 21:01HegemonKhan-
Thanks for the typo catch. That fixed it.
As far as using AND versus OR, I must use the comparator And to compare the current hour against 4 conditions, 2 of those being two separate ranges of hours. Or would not accomplish that.
Thanks for the typo catch. That fixed it.
As far as using AND versus OR, I must use the comparator And to compare the current hour against 4 conditions, 2 of those being two separate ranges of hours. Or would not accomplish that.
HegemonKhan
22 Apr 2016, 22:3390% of the time, it's always some small, stupid, simple mistake/typo in the code, rather than some major messup with with the code or its design, lol.