Major update: Fixes and expressions

Read and comment on the latest community news and site updates.
Locked
User avatar
Unas
Admin / Site programmer
Posts: 8850
Joined: Tue Jul 10, 2007 4:43 pm
Gender: Male
Spoken languages: Français, English, Español
Contact:

Major update: Fixes and expressions

Post by Unas »

Editor and game update ! :
  • In game, bugfix : now, when a text is hidden, the following messages to which it's merged won't be read.
  • In the editor, actions are now sorted by "type" categories, to help you find the action you want more easily.
  • And, the most important feature : the game has been updated with the capability to evaluate expressions. For those who do not understand, don't worry : it's not needed to use the editor as usual, but for people who wanted to be able to do more things with variable, it can come handy.
    It also goes with a new action "evaluate condition", to which you have to provide a boolean expression that will be evaluated and redirect the player.

So, since expressions are a bit particular, I'll give basic info about how to use them. There are two practical examples in paragraph 6).

1) Where can an expression be used ?
An expression can be used
  • In the action "evaluate condition", as first argument
  • In the action "Test a variable's value", as both variable to test and value to compare to. In this action, you have to indicate you're using an expression by writing 'xpr=' at the beginning of the argument.
  • In "Define a variable", the value will be interpreted as an expression if it begins with 'xpr='.
About Test and Define variable, I'll give examples later.

2) How does an expression work ?
The idea is simple : like a calculator. You know, if you type '1 + 1 * 2' in a calculator, it will output 3. It's the same here.
It can use variables as input. For example, if you defined the variable "smurf" to the value 1, '1 + smurf' will evaluate to 2.

3) How must an expression be written ?
There's a precise - but simple - syntax to follow.
  • Numbers and operators can be entered as-is.

    Code: Select all

    1 + 5
    will output 6
  • Strings must be entered between simple quotes

    Code: Select all

    'I am ' . 18 . ' years old'
    will output I am 18 years old
    If your string contains a simple quote, escape it with backslash :

    Code: Select all

    'I\'m saying hello'
    will output I'm saying hello.
  • Simple variable names (that contain only lower-case, unaccented letters) can be entered as-is .

    Code: Select all

    1 + smurf
    will output 2 if smurf is set to 1
  • Complex variable names (with spaces, etc.) have to be double quoted.

    Code: Select all

    "My variable"
    will output the content of the variable named My variable.
    If your var name contains a double quote, escape it with backslash :

    Code: Select all

    "This is \"plop\" !"
    will output the content of the var named This is "plop".
  • Binary operators have their own priority order, but you can use parentheses to change it and group terms.

    Code: Select all

    1 + 3 * 8
    will output 25, whereas

    Code: Select all

    (1 + 3) * 8
    will output 32
  • There are special functions that can be called with f: followed by the function's name, and its arguments in parentheses, separated by commas.

    Code: Select all

    f:evidence_is_revealed('preuve', 1)
    will output true if the player can see evidence 1, else false.
4) What operators can be used ?
  • - as unary operator to take the opposite of a number. Ex :

    Code: Select all

    -5
  • ! as unary operator to take the opposite of a boolean. Ex :

    Code: Select all

    !true
    will return false.
  • +, -, *, /, %, ^ as binary operators for basic operations on numbers. / is the integer division, % the modulo, and ^ the exponent. Ex :

    Code: Select all

    5 - 8 + 7 ^ 2
  • =, !, <, > as binary operators to compare objects. By the way, a ! b means "a is different from b" Return a boolean.
  • . to concatenate two strings. Ex :

    Code: Select all

    'I am ' . 'fine !'
  • &, | to operate on boolean. & means 'and' and | means 'or'. Ex :

    Code: Select all

    (1 = 3) & plop
    will always output false, whatever the content of plop is, since 3 is never equal to 1 :P
5) What special function can be called ?
  • str_begins_with. takes two arguments, and checks if the second one is at the beginning of the first one. Returns a boolean. Ex :

    Code: Select all

    f:str_begins_with('plop', 'pl')
    will return true.
  • str_ends_with. Idem, but at the end of the string. Ex :

    Code: Select all

    f:str_ends_with('plop', 'op')
    will return true.
  • str_contains. Idem, but anywhere in the string. Ex :

    Code: Select all

    f:str_contains('plop', 'lo')
    will return true.
  • str_first_word. Extracts the first word of a string. Ex :

    Code: Select all

    f:str_first_word('Apollo Justice')
    will return Apollo
  • evidence_is_revealed. Checks if the player can see a piece of evidence. Takes two parameters : the type and id. The type is 'preuve' for evidence, and 'profil' for a profile. Returns a boolean Ex :

    Code: Select all

    f:evidence_is_revealed('preuve', 1)
    checks if evidence 1 is in the record, returns true then, or else false.
Of course, functions about strings will be more useful when I'll add a user prompt feature, but it won't be done before a while :mrgreen:

6) Practical examples
For those who just want to do basic things and do not understand the rest of it, or for those who don't really get it and need more examples, here we go :

a) How to check an evidence is revealed and redirect the player ?
-> Use the "evaluate condition" action, with that expression :

Code: Select all

f:evidence_is_revealed('preuve', 1)
to check if evidence 1 is revealed. Set the id of the text to go if it's a success, ie if the evidence is visible, and the other one for a failure.
You can check for several evidences a the same time by doing like that :

Code: Select all

f:evidence_is_revealed('preuve', 1) & f:evidence_is_revealed('profil', 5)
It will check for evidence 1 and profile 5.

Code: Select all

f:evidence_is_revealed('preuve', 1) | f:evidence_is_revealed('profil', 5)
will check for evidence 1 or profile 5.

b) How to increment a variable ?
If you want to increment a variable, to count the number of times the player saw a message for example, you have to use the "define variable" action.
Let's say you want to add 1 to the variable name count, you'll have to do
Define variable
Variable's name : count
Variable's value : xpr=count + 1
Don't forget the 'xpr=' at the beginning to indicate you're using an expression.


Here's basically how it works, I hope it's not too hard to understand :D
ImageImageImage
If knowledge can create problems, it is not through ignorance that we can solve them.
Si le savoir peut créer des problèmes, ce n'est pas l'ignorance qui les résoudra. ( Isaac Asimov )
Locked