A fixed macro repeats actions. A more useful macro can also remember what has already happened: how many times it tried an operation, whether a warning appeared, or which path should run next. That memory prevents a flow from treating every cycle as if it were the first.
EmuloMobile provides macro-level variables for this job. You can create text, number, and boolean values, update them during execution, and use By Variable conditions to control individual steps or a compound block. Everything is configured in the visual builder on Android.
This guide assumes that you already have a small macro to edit. If you are starting from zero, first see how to build Android automation directly on the device.
What a variable adds to an Android macro
Visual conditions answer questions about the current screen: “is this image visible?”, “does this text appear?”, or “did this area change color?”. A variable answers a different question: “what has this macro already learned or counted during this run?”
This distinction makes several patterns possible:
- limit how many times a step can be attempted;
- count completed items or processed screens;
- remember a choice as text;
- mark whether a one-time action has already run;
- change an amount with a numeric expression;
- combine internal state with image, text, or color conditions.
Variable values start from their configured defaults at the beginning of each execution or test. They are runtime memory for the macro, not a permanent database between separate runs.
Choose the variable type before building the condition
EmuloMobile supports three variable types. Pick the type according to the decision the flow needs to make.
Number
Use a number for counters, quantities, and arithmetic. A number can be an integer or decimal, and you can choose whether negative values are allowed.
Numeric variables support equality and inequality checks plus greater than and less than. When you set a new value, you can enter an expression such as attempts + 1 or (items * 2) + bonus.
Boolean
A boolean is either true or false. It works well for state such as warning_seen, logged_in, or first_cycle_done.
Boolean conditions can check whether the current value equals or does not equal the expected value.
Text
Use text for a label, mode, route, or other short value that does not require arithmetic. Text conditions support equals, not equals, contains, and does not contain.
Variable names used in numeric expressions must start with a letter or underscore and contain only letters, numbers, and underscores. Names such as attempts, item_count, and total2 work well because their purpose stays clear in both the editor and the expression.
How to create a counter in EmuloMobile
The following example limits a compound attempt block to three executions. The block can contain the real action you want to retry, followed by an update to the counter.
1. Create the variable
Open the macro in the builder and add a Set Variable action. In its editor, select Manage variables, then New variable.
Configure it like this:
- Name:
attempts - Type: Number
- Subtype: Integer
- Allow negatives: off
- Default value:
0
Create the variable. The default means every new macro execution begins with zero attempts.
2. Put the attempt actions in a compound block
Add a Compound Action and place the action you want to limit inside it. This could be a tap, swipe, or another supported step. Keeping the attempt inside one block makes it possible for a single condition to gate the whole group.
At the end of the same compound block, add Set Variable, choose attempts, and enter:
attempts + 1
The current value is read, one is added, and the result becomes the new value. You do not need a separate arithmetic step.
3. Add the limit condition
Add a condition to the compound block, choose By Variable, and configure:
- Variable:
attempts - Operator: less than
- Compare with:
3
The block can run while the counter is 0, 1, or 2. After the third pass through the block, attempts becomes 3 and the condition stops admitting another attempt.
4. Handle the limit explicitly
After the compound block, add the action that should handle the limit, such as a notification or screenshot. Gate it with a second By Variable condition: attempts equals 3.
If the surrounding flow repeats, reset the counter after handling the limit or set a second boolean to mark that the handler has run. Otherwise, an action gated only by attempts = 3 remains eligible on later cycles.
Condition first, action second: avoid a logical deadlock
EmuloMobile evaluates a step’s conditions before executing its action. This is important when the same variable appears on both sides of the step.
Suppose attempts starts at 0 and a Set Variable step should change it to 1. If you add attempts > 0 as the condition on that same step, it will never run: the condition waits for a value that only the blocked action could create.
Use one of these structures instead:
- update the variable in an earlier, unconditional step;
- let a visual condition trigger the update, then use the new value on a later step;
- gate a compound block with the current value and update the variable inside that block;
- ensure another valid path can change the value that the condition is waiting for.
This ordering is also why the counter example checks attempts < 3 on the compound block and increments the counter inside it.
Expressions and comparisons you can use
For numeric values, Set Variable accepts calculations with other numeric variables. The engine supports addition, subtraction, multiplication, division, floor division, remainder, powers, and parentheses.
Practical examples include:
attempts + 1to increment a counter;remaining - 1to reduce a quantity;unit_price * itemsto calculate a total;(successes * 100) / attemptsto calculate a rate whenattemptsis not zero;index % 2to alternate between two paths.
The variable condition editor filters operators by type:
- number: equals, not equals, greater than, less than;
- boolean: equals, not equals;
- text: equals, not equals, contains, does not contain.
Keep expressions short and protect divisions with a preceding condition that excludes zero. A clear flow is easier to test than a dense formula hidden inside one step.
Three practical variable patterns
Run a setup action only once
Create a boolean named setup_done with default false. Gate the setup block with setup_done = false, then set it to true at the end of the block. On the next cycle, the setup block is skipped.
Change behavior after a threshold
Create an integer counter named processed. Increment it after each completed item. Gate the normal path with processed < 10 and the completion path with processed = 10.
Remember a selected route
Create a text variable named route. Set it to values such as standard or review when the corresponding screen state is detected. Later steps can use route = review without having to infer that earlier choice from the screen again.
Combine variables with visual conditions
Variables do not replace screen detection. They complement it.
For example, an image condition can confirm that a button is visible while a variable condition confirms that the macro has fewer than three attempts left. Both conditions can gate the same compound block. The visual check protects against tapping the wrong screen; the counter protects against retrying indefinitely.
Choose the simplest signal for each responsibility:
- use image, text, or color for what the interface currently shows;
- use a variable for what the macro has counted or decided during execution.
Test the flow before leaving it running
Use a short test case and check each transition:
- confirm that the default value matches the intended first cycle;
- verify that Set Variable runs only after the event you want to count;
- test the value immediately below the threshold;
- test the exact threshold;
- check what happens on the next cycle;
- stop and restart the macro to confirm that defaults are applied again;
- remove references before trying to delete a variable that is already in use.
A counter is useful only when every increment represents the event you meant to count. Place updates close to that event and name variables after their meaning, not after their position in the flow.
Give the macro controlled memory
Variables turn a visual sequence into a flow that can count, remember, and choose. Start with one small state, such as an attempt counter or a one-time boolean, and make the update and exit condition explicit. That is usually enough to replace an endless retry with a bounded, inspectable routine.
Explore EmuloMobile and build conditional Android macros directly on the device.