I am going to be teaching you how to make a toggle switch!
Let's start off by pulling up your Expression 2 STool, found under "Control".
Start by adding an Input, let's call it "A", this is how your line should look.
Let's continue by adding an output, which will be our On / Off value. We shall call this, B.
Now for our code.
We will be using the operator, +=, which means, Increment Value C by D ammount. It looks like this.
Along with the increment, we will be using an If Then statement that follows the pattern of..
Code:
if(Input==E){Output=F} Back to our project, let's apply these principles!
What we just did is, If any input other than 0 is inputted (Remember, A is our input), then Increment B by 1.
Now for the reset.
If Value B is greater than 1, then it reset to 0.
Your code should look something like this.
Code:
@name Toggle
@inputs A
@outputs B
@persist
if(A){B+=1}
if(B>1){B=0}
This works by incrementing B until it is greater than 1, and resets it back to 0. Wire up a button to A (A non toggle button), and B to a screen.
As you press the button, the value changes to 1. If you press the button, it resets to 0 because it will have incremented to a value greater than 1.
^^ That is my tutorial.
Bookmarks