Tutorial #2

Scripts

The focus here is on script.

1. About the TOMATE Script

The TOMATE script provides the following unique commands.

ClassificationContents
[ ]Show variables
< >Move page
( )Variable operation
xxx{ }Commands
” “Output to “OUTPUT.TXT”

Use the following symbols as delimiters:

SeparatorContents
: (colon)Command delimiter
or Separate items in commands
, (comma)Separation of setting values in commands.

Multiple commands can be used for one object by separating each command with a colon “:”.

Example:
  (cnt+=1) : <@next> : "Next page"

When an object is touched, cnt+=1, move to the next page, and output 'Next page' strings to "OUTPUT.TXT" file.

 

Basically, there is no need to distinguish between character strings and numeric values for characters handled in the TOMATE script.

 Using single quotes ‘ ‘ treats everything as a string, including numbers.
Parentheses, commas, and colons used in the TOMATE script must be enclosed in single quotes when used in strings.

There are two types of TOMATE scripts.

ContentScript reference icon
What is reflected in the constant displayテキスト, アイコン  自動的に生成された説明
Execute when touch operation or input to “INPUT.TXTアイコン  自動的に生成された説明黒い背景に白い文字がある  中程度の精度で自動的に生成された説明

 About the Script Reference
For more information on scripts, see “Script Reference”.

https://www.clues.jp/tomate/Tomate-Reference_EN.htm

It is displayed by specifying “Help: Script Reference” from the app menu.

2. Script reflected in display

Let’s actually create it.

Draw a suitable object and write [cnt] in the script field of that object.
This will display the value set in the variable  cnt within that object.

Enter [cnt] in the script field of the display object

 The script [variable name] is a command that displays the variable value.
  

If you use a variable in your script, enter the variable name in the “Variables” area.

In the variable field, you can enter the initial value of the variable with ‘=’.

If the variable value contains only numbers, it will be treated as a numerical value, and if it contains a character string, it will be treated as a character string.

Enter “cnt=0” here.

Enter cnt=0 in the “Variables” field

  The variable settings are a=b=c=0, etc.
A variable name can be written continuously with an equal sign.
Initialized to the value written to the end.

Entering an initial variable value will change the string in the drawn object to that variable value.

At this time, the character format displayed in the object will be the format set in the “Information Tool”.

Change font in “Information tool”

3. Script reflected in touch behavior

Now let’s write a script for touch actions.

Draw a button object and enter the following in the script field.

 (cnt+=1):var{cnt:1}
Enter (cnt+=1) in the button object

 Parenthesized script (expression)
   

A command that performs variable operations.
TOMATE only uses the assignment operations such as ‘+=’ and ‘-=’.
The left side is always a variable, that is no need to enclose it in [ ] .  
When writing a variable on the right side, it is necessary to enclose it in [ ].

 The command of ‘var{ }’

This command outputs variable values to ‘OUTPUT.TXT’.
If you put the ‘:1’ flag inside like ‘var{cnt : 1}’
Output with variable name.

Each time this object is touched (clicked), it is cnt+1, and the display value of the display object changes according to the change of cnt.

4. Test run

When the creation is complete, press the tool button or operate “Menu: Run: Test” (F5 key).

I/O window
Test window

A test window will appear, and each time you press the PUSH button on the screen, the display will increase by one.
Furthermore, the value of the variable cnt is displayed in the ‘Output.txt’ field of the I/O window.

4-1. Input/Output interface

TOMATE can communicate with external programs using two files, Input.txt / Output.txt, as an external interface.

These two files are automatically created in the folder where TOMATE is running.

Input.txtInterface for inputting commands to TOMATE from external program.
Output.txtInterface for outputting information from TOMATE to the external program.

By reading the contents of ‘Output.txt’ from an external program, you can read the operation contents and variable contents on TOMATE.

You can also issue instructions to TOMATE by writing commands to ‘Input.txt’ from an external program.

In the I/O window, you can check the contents of ‘Output.txt’, write commands to ‘Input.txt’, and check the operation.

 Only commands marked with an icon 黒い背景に白い文字がある  中程度の精度で自動的に生成された説明 in the script reference can be written to ‘Input.txt’.

For example, enter ‘msg{Hello}’ in the ‘Input.txt’ field and press the [Write] button.

A message box with ‘Hello’ will open on the ‘Test window’.

Result of typing ‘msg{Hello}’ in ‘Input.txt’ field

  The command of ‘msg{ }’
It is a command that can easily display a message.  
You can arbitrarily set the number of buttons and characters to be displayed on the buttons.  
If nothing is specified, only the [OK] button will be displayed.
The message box is disappeared when the button is pressed.