Need help with E2

what is the code for
is in range
is not in range

and if i were to have 4 cannons how can i toggle between them with one button and have a hint telling me what cannon is selected?

make a cannon or something else happen if i were to say fire but not fire in a sentence

oh and timing in e2 (ex. if a is pressed then wait 10 seconds then fire)

@name Cannon Ranger
@inputs Selector PsuedoInput
@outputs Cannon1 Cannon2 Cannon3 Cannon4
@persist CannonSel

# This makes it do something when people talk

# Selecting between four cannons
if (Selector) { # Wire Selector to a non-toggle button
  if (CannonSel == 4) {
    CannonSel = 1 # If we're at cannon four, go to cannon 1.
  else {
    CannonSel ++ # Raise the cannon number higher otherwise
    # There's probably a shorter way of writing that, but I don't care
  hint("Selected cannon " + toString(CannonSel) + "", 4) # Hint will display for four seconds.
  # Feel free to change the number, but you're limited between 0.7 and 7

# Put this in your E2 if you want to check isinrange
if (PsuedoInput > 1 & PsuedoInput < 10) { # Is inside range between 2-9
  print("PsuedoInput is in range!!!")

# Put this in your E2 if you want to check isnotinrange
if (PsuedoInput < 10 & PsuedoInput > 50) { # Is outside range between 10-50
  print("PsuedoInput is out of range!!!")

if (owner():lastSaid() == "fire" & chatClk() == 1) {
  # This will execute if someone says something and the
  # last thing you said was "fire", in and of itself
  # First, we set a turn off timer.
  timer("ShutMeOff", 1000) # 1,000 milliseconds == 1 second
  if (CannonSel == 1) { Cannon1 = 1 }
  elseif (CannonSel == 2) { Cannon1 = 1 }
  elseif (CannonSel == 3) { Cannon1 = 1 }
  elseif (CannonSel == 4) { Cannon1 = 1 }

if (clk("ShutMeOff")) { # If the "ShutMeOff" timer is triggered"
  Cannon1 = 0
  Cannon2 = 0
  Cannon3 = 0
  Cannon4 = 0

lavacano, let me comment your code:

Here’s a shorter way of writing that:
Longest way: CannonSel = CannonSel + 1
Shorter way: CannonSel += 1
Shortest way: CannonSel ++

You don’t need to use toString. It automatically converts numbers into strings (At least in my experience). I also suggest using “print()” instead of “hint”. Well, it’s personal really… but I like print more.

You have changed the wrong number. All of them say “Cannon1 = #”
You have also forgot to reset them all to 0 after firing, so they will fire continously forever and ever.

ok thanks but can someone tell me timers and isinrange, isnotinrange?


oh and how do i wire that?

Revising code per Divran’s post…done

Commenting where I put the is in range and is not in range stuff

ah man onacaval,

thank you so much because of your code i learned so much and just thank you…

P.S. i revised your code and now it works 100% and i can toggle between 1,2,3,4,all with the hint saying cannon 1-4 and all


also, one last thing,

how can I make the four cannons fire like a gatling gun(make them fire in a way so that a cannon is always hitting the thing im aiming at)