How to do a "first run" initialization?


#1

2) What is the expected behavior?

I have a piston which I want to be stateful between executions. So, I define a boolean (‘boolFirstExecution’) and InitialValue is left at Nothing Selected (no value). I want to set it to true on the very first run and false on every future run.

3) What is happening/not happening?

If I were to initialize the value, I understand it gets reset on each piston execution.

I was looking through system variables in hopes of finding one I could use. Are $currentEventDate and $previousEventDate both not initialized on first run? Just looking for the cleanest viable option.

Could I do this psuedocode?

if (boolFirstExecution is not true) and (boolFirstExecution is not false)
then
Do my one time init
Set boolFirstExecution = true

Thanks!


#2

Instead of all that fancy footwork, I sometimes just cheat and add a line under execute saying:
Set variable to true

I run the piston once, (to set the variable) and then edit and delete that line. From that point onwards, it will follow the code you have in place.


Or, the lazy man’s way is, instead of using:
If variable is true
You can use:
If variable is NOT false

This slight change of wording will execute if the variable is true or not set.


#3

Or once you save the piston, go to the variables section of the piston view.

Click on the box with the pencil on it.

And choose the value that you want from the drop down.


#4

Erghh … you really could have pointed that method out to me about 323 pistons ago. :rofl::rofl:


#5

Much appreciated, all workable solutions. I had already basically implemented a daily timer with a global time variable so I could initialize any pistons I had written by just setting the timer and waiting a couple minutes.