Variable help initial value


#1

Is there is way to assign an initial integer value to a variable like the one below

and then later on in the piston, write an expression to plus 1 that variable?

I know it will work if I leave the initial value blank, (it will start at 1 and go up), but I want to start the number at “29” and then plus one from there, but it’s not working when I set an initial value of 29…
Thanks!


#2

I’d add statement to check if value is less than 29, then set variable to 29 be if false. That would be my suggestion.


#3

I’m not sure if I expressed my issue clearly. I’d like to start off the variable at the number 29, but it doesn’t do the math (washerCountMonth+1) correctly when i do that. It only does the math correctly if I don’t set an initial value…


#4
If var < 29
  Set var = 29
Else
  Set var = var+1

That’s what I had in mind. Assuming you have var as unassigned to start.


#5

I see now. Thanks!


#6

Fun fact, in the variables section of a piston, you can click on the tiny little pencil icon and it will allow you to set the value for any variable that you’ve defined. So that could absolutely be done to set your initial value…and then your piston will chug along adding as it goes. This eliminates the need to add special code and then remove it.

image