(Redirected from () - () (block))

() - ()
(() - ())
Category Operators
Type Reporter
Introduced in 11Oct03 (0.x)

The () - () block is an Operators Block and a Reporter Block. The block subtracts the second value from the first and reports the result.

Example Uses

The block is mainly used for calculations where subtraction is needed.

Some common uses for the () - () block include:

  • Scripts in calculator simulations
ask [What is your first number?] and wait
set [First Number v] to (answer)
ask [What do you want to subtract from that?] and wait
say (join [The answer is: ] ((First Number) - (answer)))
  • Math formulas
set [Distance Apart v] to ([sqrt v] of (((([x position v] of (Sprite1 v)) - ([x position v] of (Sprite2 v))) * (([x position v] of (Sprite1 v)) - ([x position v] of (Sprite2 v)))) + ((([y position v] of (Sprite1 v)) - ([y position v] of (Sprite2 v))) * (([y position v] of (Sprite1 v)) - ([y position v] of (Sprite2 v))))))
say (join [The distance from Sprite1 to Sprite2 is: ](Distance Apart))
  • Swapping positive and negative values
set [my variable v] to ((0) - (my variable))
  • Creating a compact script for a button
when gf clicked
set [Song on? v] to (1)

when this sprite clicked
set [Song on? v] to ([1] - (Song on?)) // flips the variable between 1 and 0
if <(Song on?) = [1]> then
  play sound (This is a party! v) until done
else
  stop all sounds
end

Workaround

Main article: List of Block Workarounds

The block can be replicated with both of the following:

((a) + ((b) * (-1)))
((a) + (join [-] (b)))

a is the starting number, b is the number to be subtracted, and the resulting number is the result of the subtraction.

See Also

Cookies help us deliver our services. By using our services, you agree to our use of cookies.