-2
   if bulletsOn == true {
            bullets -= 0.003
        } else {
            bullets += 0.001
        }

when I put in form of ternary like so, I get error from compiler.

    bulletsOn ? bullets -= 0.003 : bullets += 0.001

error: Result values in '? :' expression have mismatching types '()' and 'CGFloat'

andrewJames
  • 19,570
  • 8
  • 19
  • 51
  • 2
    `bullets = bulletsOn ? bullets - 0.003 : bullets + 0.001` – jnpdx Feb 09 '22 at 18:39
  • 4
    `bullets += bulletsOn ? 0.001 : -0.003` –  Feb 09 '22 at 19:08
  • The issue there is the lack of a parentheses. `bulletsOn ? (bullets -= 0.003) : (bullets += 0.001)`. Btw `bulletsOn ? bullets -= 0.003 : (bullets += 0.001)` would work as well – Leo Dabus Feb 10 '22 at 02:40

1 Answers1

1

Ternary are just funny math operations so you need a value two be assigned to, a condition and the two values that can be assigned to it, but your two condition don't even return values, so

bullets += bulletsOn ? -0.003 : 0.001

would work

Nathan Day
  • 5,981
  • 2
  • 24
  • 40