CardMaker Tutorial: Element: Definition Variables and Logic

This guide covers the transtion variables and logic you can use in a Definition. There is a lot of duplication from the manual. Translation variables are specially formatted blocks of text that are translated before rendering to display something else (much like a reference to a column).

  1. The following translation variables and logic apply to all types of Elements: (the samples below are Text Element output)
    • Counter
      Format: ##x;y;z#
      This will translate as follows: x + (current card index * y) with left padded 0's numbering z
      Note: The card index is a 0 based value. This can be a bit confusing but is critical to the use of the y value.
      Some examples:
        ##1;1;0# -- Just a basic counter starting at card index 1
      • Card 1 Result: 1
      • Card 33 Result: 33
      • Card 100 Result: 100
        ##5;1;3# -- Counter starting at 5, with left padding.
      • Card 1 Result: 005
      • Card 33 Result: 037
      • Card 100 Result: 104
        ##2;2;0# -- Counter starting at 2, and adding 2 per card index.
      • Card 1 Result: 2
      • Card 33 Result: 66
      • Card 100 Result: 200
    • If Statement (see the manual for more details)
      Formats:
      #(if x [logical statement] y then a)#
      OR
      #(if x [logical statement] y then a else b)#
      This will translate based on the success/failure of the logic statement. There are a number of possible logical operators detailed in the manual.
        Some examples:
      • #(if 1 == 1 then good news!)#
        Result: good news!
      • #(if 1 == 2 then bad news!)#
        Result: There is no result because 1 does not equal 2.
      • ++#(if 1 == 2 then bad news!)#++ -- The logical statement will result in nothing but the existing text wrapped around it will appear as normal.
        Result: ++++
      • ++#(if 1 == 2 then bad news! else good news!)#++
        Result: ++good news!++
      • ++#(if 1 == then bad news! else good news!)#++ -- This logical statement is comparing 1 to an empty string. As they are not equal this will fail to the else value.
        Result: ++good news!++

        Note: If the comparison or results contain the key words: else or then you might run into trouble. Yikes!
        If you need to do something that really requires that kind of output I recommend investigating the
        override:[Element name]:variable as a way to override the Definition value of the Element.
    • If Statement (grouped) (see the manual for more details)
      Formats:
      #(if [x;y;z] [logical statement] [a;b;c] then m)#
      OR
      #(if [x;y;z] [logical statement] [a;b;c] then m else n)#
      This will translate based on the success/failure of the logic statement based on the existence of x, y, or z in the set of a, b, and c. Only one of the values in the first set must exist in the second set to pass. Both sets are unbounded on size. Only the == and != logical operators are supported for this logic. This is a reasonably complex statement to use and is only recommended if you really need it!
        Some examples:
      • #(if [1;2] == [5;2;6] then good news! else bad news!)#
        Result: good news!
      • #(if [1;2] == [5;6;7] then good news! else bad news!)#
        Result: bad news!
      • ++#(if [1;2] == [5;6;7] then good news!)#++
        Result: ++++
    • Switch Statement (grouped) (see the manual for more details)
      Format:
      #(switch;key;keytocheck1;value1(unbounded repeat: ;keytoCheck;value))#
      Optionally you may specify #default to indicate that if nothing passes to use the value specified with default.
      This will translate to the value associated when the key matches a keytocheck.
        Some examples:
      • #(switch;1;1;good news!;2;bad news!)#
        Result: good news!
      • #(switch;2;1;good news!;2;bad news!)#
        Result: bad news!
      • ++#(switch;54;1;good news!;2;bad news!)#++ -- Unlike the if statements the result of a unfound item is the raw text (might be something to consider changing in the application!).
        Result: ++#(switch;54;1;good news!;2;bad news!)#++
      • #(switch;3;1;good news!;2;bad news!;#default;confused!)#
        Result: confused!


© Copyright NHMK 2018    e-mail: nhmkamv at gmail
(Pages on this site use Javascript so if you do not see content you have Javascript disabled!)