logical operators in quest expressions?

Good morning,

I want to do the following: I have a command "change size #text#" which the player can use to change the font size. It does this correctly if I enter an integer - but what if I enter: change size bleh - obviously, the size doesn't get changed, however the game doesn't return an error, either.

I have no clue why someone would enter texT if asked for a numeric input, but better save than sorry.

My first guess was to add something like: if text >= 1 && text <= 75 and for the rest the unresolved object text fires (or I add an else if this isn't the case)...
This would have two problems, though: Is quest intelligent enough to convert a string to int to check whether it matches or do I have a java-style type mismatch then? And: What logical operators does quest use? In Java, JavaScript, C++ etc. it's && for and, || for or, ! For not... In SQL we use AND, OR and NOT. What are the logical operators for quest?

Thanks in advance.

Yours,
Tim


You should use IsInt to check if a string can be converted to a number, and ToInt to convert it if it can. Comparing a non-numeric to a numeric will throw an error.

Quest uses or, and and not.


here's some of the quest doc stuff (what quest has already built-in for you to use):

there's these scripts/functions for checking/converting/getting/etc various data/value/attribute/variable types:

'IsXXX (xxx)'
'ToXXX (xxx)'
'HasXXX (xxx)'
'GetXXX (xxx)'
'TypeOf (xxx)'
'DoesInherit (xxx)'

http://docs.textadventures.co.uk/quest/ (main page, look/search/navigate around, and/or ask for help if you can't find something or need something and/or syntax explained)

http://docs.textadventures.co.uk/quest/scripts/
http://docs.textadventures.co.uk/quest/functions/ (categorical order)
http://docs.textadventures.co.uk/quest/functions/index_allfunctions.html (alphabetical order)

http://docs.textadventures.co.uk/quest/types/ (Data/Attribute/Variable/Value Types)

http://docs.textadventures.co.uk/quest/elements/ (quest's OOP/OOD 'OBJECTS' in the underlying quest code are called/known-as 'Elements' at its user-level, not to be confused with the 'Object' sub-Element, one of many types/sub-types, along with Exits/Functions/Verbs/Commands/Object_Types/Turnscripts/Timers/Etc, of quest's OOP/OOD 'OBJECTS')

when you click on the 'Object' Element in the link above, you get to see all of its built-in Attributes (or just click on this link, lol): http://docs.textadventures.co.uk/quest/elements/object.html


if you work in-code directly, for using 'greater/lesser than' operations/operators, you need to nest the scripting inside of the 'cdata' code tag blocks, as this tells quest to see these symbols (<, >) as 'greater/lesser than' operations/operators/symbols, otherwise it'll see them as the tag symbols, and thus see your code as royally messed up, prompting you with error messages.

// ERROR:

<object name="example_object">
  <attr name="example_script_attribute" type="script">
    msg ("Pick a number (1 to 10)")
    get input {
      if (IsInt (result)) {
        input_integer_variable = ToInt (result)
        if (input_integer_variable > 0 and input_integer_variable < 11) { // or: if (input_integer_variable >= 1 and input_integer_variable <= 10) {
          msg (input_integer_variable)
        } else {
          msg ("wrong input, try again")
          do (example_object, "example_script_attribute")
        }
      } else {
        msg ("wrong input, try again")
        do (example_object, "example_script_attribute")
      }
    }
  </attr>
</object>

// NO error:

<object name="example_object">
  <attr name="example_script_attribute" type="script">
    <![CDATA[
      msg ("Pick a number (1 to 10)")
      get input {
        if (IsInt (result)) {
          input_integer_variable = ToInt (result)
          if (input_integer_variable > 0 and input_integer_variable < 11) { // or: if (input_integer_variable >= 1 and input_integer_variable <= 10) {
            msg (input_integer_variable)
          } else {
            msg ("wrong input, try again")
            do (example_object, "example_script_attribute")
          }
        } else {
          msg ("wrong input, try again")
          do (example_object, "example_script_attribute")
        }
      }
    ]]>
  </attr>
</object>

you can NOT use the 'while' Script/Function for looping if you're getting/using user input ('get input', Commands, 'show menu / ShowMenu', 'ask/Ask', etc?). You have to re-call ('do' or 'invoke') the script/function for looping (often as, and otherwise known as, 'tail recursion'). see above code example


also, for doing 'greater/less than or equal to', the equal sign is on the RIGHT side and the greater/lesser-than is on the LEFT side (and NO space/white-space between them):

ERROR:

if (VARIABLE =< VALUE_OR_EXPRESSION) { /* scripting */ }
if (VARIABLE => VALUE_OR_EXPRESSION) { /* scripting */ }

NO error:

if (VARIABLE <= VALUE_OR_EXPRESSION) { /* scripting */ }
if (VARIABLE >= VALUE_OR_EXPRESSION) { /* scripting */ }

Log in to post a reply.

Support

Forums