Variables / If / Switch

[Variables] [If] [Switch] [Reference] [Operators]

Status, Tag, Label (Common settings)

In settings pane, tapping top icon opens settings to set the item’s state.

Set normal state.

Set skipped state, to disable the item.

Set marked state, as preferred destination.

Set last destination of Scene Check. If Scene Check does not match any scenes, the sequence starts from the item.


In Label section, tag color and name of the item can be set.

Set tag color. Default color is transparent, at the top-left in tag color palette.

Edit label.


Variables

Substitute / calculate values of Number, String, Rectangle, for the variables of FRep2 app. The designated lines will be executed in order from the top.

Post Process

On Success:

After tapping the button, select from Next, Abort, Return, Item, or tap the destination item directly in the item list of left pane.

Variable

Set the statement(s) to execute; (Variable)=(Code):(Arg1) or (Variable)=(Code):(Arg1)(Operator)(Arg2)
See Reference, Operator for Variables for definitions.

Tapping will append the new statement. Tapping the line item will start edit, at the left will discard the statement, at the right will prepend new statement. To move position, long-tap and drag.


If

Branch the sequence by condition(s) of variables. If they meets the condition(s), the sequence proceeds to On Success, and @lastif will be 1. If not, the sequence proceeds to On Fail(else), and @lastif will be 0.

Destination

On Success, On Fail(else):

After tapping the button, select from Next, Abort, Return, Item, or tap the destination item directly in the item list of left pane.

Conditions

Set the condition(s) to judge; and/or(not):(Arg1) (Operator) (Arg2)

Logical Operators: And If, Or If, And If Not, Or If Not
To prepare complex conditions, there are 4 type logical operators.

  • And If (and:) Previous condition must be met to succeed.
  • Or If (or:) New condition check starts even if the above conditions fail.
  • And If Not (andnot:) Variant of And If; the condition use the reversed result.
  • Or If Not (ornot:) Variant of Or If; the condition use the reversed result.

The first condition ignores its logical operators because they make sense only with previous condition(s). Neither of and: or: cannot be nested. If there are multiple conditions divided by or:, each section is colored in the list.

andnot: ornot: are variant of and: or:, they use the reversed result of each condition check.

See Reference, Operators for If / Switch for for definitions.

Tapping will append the new statement. Tapping the statement will start edit, at the left will discard the statement, at the right will prepend new statement. To move position, long-tap and drag the statement.


Switch

Branch the sequence by condition of variables. Each condition has respective destination. The conditions are evaluated from the top of the list, and the sequence proceeds to the destination of first met condition. When all conditions do not match, it goes to Default: destination.

The available operators are same with If statements, except for combination (and: or: etc).

Cases

List of the statement of condition and its destination.

Tapping will append the new statement. Tapping the statement or destination will start edit, at the left will discard the statement, at the right will prepend new statement. To move position, long-tap and drag the statement.

Other Case

Default:

After tapping the button, select from Next, Abort, Return, Item, or tap the destination item directly in the item list of left pane.


Reference

The values of the variables are common in all sequences, i.e. all variables can be referred / overwritten by other sequences. The values of the variables will be cleared when FRep2 service stops. The values of the referred / written variables are saved to log of the replayed record, which can be browsed from View Last Log (requires FRep2 Unlock Key).

Variable name [A-Za-z_@][0-9A-Za-z_]+

Variable name must consist of alphanumerical characters and under bar(_). First letter cannot be a number. The reserved variables as environmental variables start with @, and they are used only for arguments and some referred values.

Variables for Tasker Plugin
frep0, frep1, frep2, frep3, frep4 are passed to Tasker as temporal variables %frep0, %frep1, %frep2, %frep3, %frep4 by Tasker Event Plugin. For result of the FRep2’s replay, %frepsuccess will be 1 for success or 0 for fail / interruption, %freplastseq will have last replayed item number and label in the sequence (or empty if the non-sequence record is replayed).
Value Type [(Empty), Number, Rectangle, String]

There are 4 value types including empty (null) value. The type of variables are determined by the value they have.

TypeDescriptionExample
(Empty)The state of no value defined.
*Shown as null in Log.
var=num:
var=rect:
var=str:
NumberInteger or decimal, including negative value.var=num:0
var=num:0.012
var=num:-0.5
RectangleRectangle defined by: (left top right bottom)
Each component must be integer or variable.
var=rect:(10 20 30 40)
StringString defined by: “character sequence”
Escaped characters; (line feed:)\n (tab:)\t (\backslash:)\ (“quote:)\”
var=str:”line1\nline2″
@reserved environmental variables

System variables for referring the state of device or playing sequence.

NameTypeDescription
@repeatNumberCurrent repeat number (0 for first time)
@loopNumberLast loop count number (0 for first time)
@lastifNumberLast IF result (success/true:1, fail/false:0)
@rotationNumberCurrent orientation of the device
(0: 0°, 1:90°, 2:180°, 3:270°)
@startNumberStarting time (ms)
@nowNumberCurrent time (ms)
@lastfinishNumberSuccess of failure of last replay
(0:not replayed, -1:failed/interrupted, 1:successful)
@laststepNumberStep No. in Edit Sequence on last replay finish
(0 if it is not replayed)
@lastmatchRectangleLatest successful Image Match position
@screenRectangleScreen size of the device (for orientation 0°)
@clipboardStringContents of the clipboard text (for reference)
*To set clipboard, use Set Clipboard control.
(If app change occurs on Android 10~,
refer the Clipboard access in System Settings.)
@labelmatchStringLatest successful Image Match’s
control sequence No. and label.
@lastocrStringLatest recognized string by OCR control.
*Includes string which numeric conversion failed.
@labelocrStringLatest string-recognized OCR’s control sequence No. and label.
*Includes failed case only numeric conversion failed.
@lastswStringLast satisfied statement of Switch, or “default” if not satisfied.
@tofrepStringText passed by the caller, by FRep2 Tasker Plugin
(Empty when started manually or with shortcut)
Special modification for variables; var.left, var.x, var.length

For some types of variables, the derived values can be referred by special postfix modification.

ModificationDescriptionExample
(Rect).left
(Rect).top
(Rect).right
(Rect).bottom
Refer each component of the rectanglel=num:r.left
(Rect).x
(Rect).y
Refer the center x or y of the rectangle
x=(left+right)/2
y=(top+bottom)/2
centerx=num:r.x
(Rect).width
(Rect).height
Refer the width or height of the rectangle
width=right-left
height=bottom-top
w=num:r.width
(String).lengthRefer the length of the stringlen=num:s.length
(String).asnum
(String).asrect
Refer the number from numeric string
Refer the rectangle from
“(left top right bottom)” type string
n=num:s.asnum
r=rect:s.asrect
(String).asint
(Num).asint
Refer the integer number
(truncated after the decimal point)
i=num:s.asint
j=num:n.asint
(Num).asstr
(Rect).asstr
Refer the number / rectangle as strings=str:n.asstr
s=str:r.asstr
(Num).asdate
(Num).astime
Refer the time (ms) number as date string
with format “yyyy/MM/dd kk:mm:ss”
Refer the time (ms) number as time difference
string with format “hour:min:sec.ms”
s=str:@now.asdate

t=num:@now–@start
s=str:t.astime

Operators for Variables

num: Set / Calculate Number

OperatorArg1Arg2DescriptionExample
(None)Variable, Number(None)Set number valuevar=num:0
+ – *Variable, NumberVariable, NumberAdd Subtract Multiplyvar=num:var + 1
/Variable, NumberVariable, NumberDivide
(If Arg2 is 0, result is Arg1)
var=num:var / 3
%Variable, NumberVariable, NumberResidue
(If Arg2 is 0, returns 0)
var=num:var % 3
& | ^Variable, NumberVariable, NumberBit operation AND OR XOR
(Args are forced to be integer)
var=num:var & 7
~Variable, NumberVariable, NumberBit operation ANDNOT
(Args are forced to be integer)
var=num:var ~ 128

rect: Set / Calculate Rectangle

OperatorArg1Arg2DescriptionExample
(None)Variable, Rectangle(None)Set rectangle valuevar=rect:(0 0 100 200)
+ – *Variable, RectangleVariable, Number, RectangleAdd Subtract Multiply
*If Arg2 is rectangle, each component will be used for calculation. If Arg2 is number, it is applied for all components.
var=rect:var + (10 20 10 20)
*Move the var rectangle by (10,20)
/Variable, RectangleVariable, Number, RectangleDivide
*If Arg2 is rectangle, each component will be used for calculation. If Arg2 is number, it is applied for all components. When the component is divided by 0, it will not change.
var=rect:var / (2 2 0 0)
*Halve the (left, top) coordinates
&Variable, RectangleVariable, RectangleIntersect
Retrieve common area in both rectangles.
var=rect:var & @screen
*Clip by screen size
|Variable, RectangleVariable, RectangleUnion
Retrieve the minimum area which covers both rectangles.
var=rect:var | @lastmatch
*Expand rectangle to contain image matched area

str: Set / Calculate String

OperatorArg1Arg2DescriptionExample
(None)Variable, Number, Rectangle,
String
(None)Set String valuevar=str:”char seq”
+Variable, Number, Rectangle,
String
Variable, Number, RectangleConcatenate 2 values as stringvar=str:var + “\n”
*Append line feed
subVariable, StringRectangleExtract string from Arg1, as defined range of Arg2 (la ln ca cn).

When ln>0, extract ln lines from offset:la.
When cn>0, extract cn characters from offset:ca.

*If la<0 or ca<0, each extraction starts from back position from tail.
var=str:var sub (1 2 5 10)
*Extract 2 lines from var, offset:1 (#2,3 line) and then get 10 characters from 6th.

var=str:var sub (a 1 0 0)
*Extract line #(a+1) from var.

var=str:var sub (0 0 -5 5)
*Extract last 5 characters from var.
idxVariable, StringVariable, StringIf Arg1 contains Arg2 string, the position of Arg2 start in Arg1 string (first is 0).
If Arg1 does not contain Arg2 string, -1.
var=str:”abcde” idx “cd”
*var is set to 2 (num).

var=str:”abcde” idx “f”
*var is set to -1 (num).
replaceVariable, StringVariable, StringConverts all strings contained in the destination variable that match Arg1 to Arg2 (Regular Expression)var=str:”12:34;”
var=str:”[;:]” replace “”
*var is set to “1234”
readVariable, String(None)Read the file designated by the path of Arg1. (up to 1MB)
*The file path must be an accessible for FRep2 app
var=str:”/sdcard/test.txt” read

Functional Codes

CodeArg1Arg2DescriptionExample
toast:Variable, Number,
Rectangle, String
(None)Show the message by popup.toast:”message”
clean:(None)(None)Clear all variables except environmental ones(@~).clean:

Operators of If / Switch

OperatorArg1,2Description
==
!=
Variable, Number,
Rectangle, String
Check if the contents of Args are equal or not equal.
ex.)and:var == “char seq”
and:@loop == 0
Success when var is “char seq”
Success during first loop (after start, before end).
> >=
< <=
Variable, NumberCompare the numeric values.
ex.)and:var > 0Success when var is greater than 0.
&Variable, Number,
Rectangle
If Args are numbers, success on the result of BITAND
operation is not zero. If Args are rectangle, success
on any intersect area exists.
ex.)and:var & 5
and:r & @lastmatch
Success when var BITAND 5 != 0.
Check if the result of Image Match hits on r or not.
]=Variable, Rectangle,
String
If Args are rectangle, success when Arg1 equals or
includes whole Arg2 area.
If Args are string, success when Arg1 contains Arg2 string.
ex.)and:r ]= @lastmatch
and:var ]= “ok”
Success when the result of Image Match is in r.
Check if var has string “ok” or not.

[↑Common Settings; Label, etc.]