Persistent variables

A variable by default is reset every time a scene is run.

That’s why most users use virtual devices to keep the status of a variable for now.

If you however want to keep a certain value, you can also write it into a file.
This then allows you to read the content of this file, the next time you execute the scene and continue from there.

You can do this in 2 simple blocks.
You use the custom PHP block for this inside blocky.

Step 1: you write the value you want to save to a file.
$file = ‘VariableName.txt’;
$current = file_get_contents($file);
$current = “Put your content here“;
file_put_contents($file, $current);

Step 2: you read the file and put this value back into your variable.
You do this when you need to retreive the value of your variable.
$file = file_get_contents(‘VariableName.txt’, FILE_USE_INCLUDE_PATH);

You can now use the real variables system (eg: create a variable named “file” in this case) to put the variable block inside IF statements.
It looks something like:
IF file = TEXT 123

You can use the php function addlog($file); in step 2 to debug the scene.
It will write the contents to your scenes log file.