BloxGaming Forums
Our Servers => BloxGaming SB3 => Expression 2 (E2) Code => Topic started by: kevinminion on September 03, 2015, 09:42:59 pm
-
I was asked if I could make an e2 chip that would take a non-toggled input, like MOUSE1 from the Pod Controller, and make it so that MOUSE1 only needed to be clicked once to turn on, and then once again to turn off.
I came up with what I think is a good solution, but it does not involve an e2 chip, I just used a toggle gate and a constant value of 1:
Constant Value location: Wire Tab > Inputs, Outptus > Constant Value * I suggest that you make this one a favorite
Toggle Gate location: Wire tab > Chips, Gates > Gates MEMORY folder > Toggle (Edge Triggered)
Using the Advanced Wiring Tool, - Wire the input OnValue of the Toggle gate to the constant value output of 1.
- Wire the input Clk of the Toggle gate to the MOUSE1 output on the Pod Controller.
- Wire the input FIRE of the weapon to Out output of the Toggle gate.
That's it!
-
So after I posted the message above, I thought it might be good to post code for those learning E2 since it's fairly simple.
@name example_e2_Toggle
@inputs OnValue OffValue Clk
@outputs Out
@persist IsOn
@trigger Clk
if (first()) {
IsOn = 0 # start off
}
if (~Clk & Clk) { # Toggle on rising edge
IsOn = !IsOn # Toggle the state of the variable IsOn
if (IsOn) {
Out = OnValue
} else {
Out = OffValue
}
}
Wire with Advanced Wiring Tool as described in the post above.
-
The method i use for pulse wire to toggle is a memory d-latch and a logic not(invert) gates.
Wire data from d-latch to the invert, wire a invert to the d latch. Wire clk from d latch to mouse 1 or whatever.
Edit: Method found/Or made by Bloxgate