(Redirected from () = ())

() = ()
() = ()
Category Operators
Type Boolean
Introduced in 11Oct03

The () = () block is an Operators block and a Boolean block. The block checks if the first value is equal to the second value. If the values are equal, the block returns true; otherwise, it returns false. This block is case-insensitive, meaning that capital and lowercase letters are treated the same.

In Scratch 1.3 and before, it only accepted numbers as values, though text variables could be used.[1]

However, if both values contain very large numbers and there is only a small difference between them, the block will sometimes return true, as seen in the below examples. Some Scratchers have suggested for this to be fixed.[2]

<[111111111111111110] = [111111111111111111]>

<[505050505050505050] = [505050505050505000]>

<[9999999999999999] = [10000000000000000]>
Comparing slightly different long numbers. All values above return true.

Example Uses

If an action must be performed if a variable equals certain amount, this block can be used.

Some common uses for the () = () block:

  • Pausing a script until a variable reaches a certain amount
when flag clicked
wait until <(score) = [10]>
say [Good job!]
when green flag clicked
ask [Was my joke funny?] and wait
if <(answer) = [yes]> then
    say [Thank you!] for (2) secs
end
  • Checking if Boolean values are the same
if < <mouse down?> = <touching (sprite 1 v)?> > then
    say [Either you are clicking and I am on sprite 1, or you are not clicking and I am not on sprite 1.]
end
  • Comparing different values
if <(x position) = (size)> then
    say [The sprite size and x position are equal.] for (5) seconds
else
    say [The sprite size and x position are not equal.] for (5) seconds
end

Comparisons

Comparing Numbers

This block will sometimes report that two very large numbers are true even if they are not.

<[100000000000000000] = [100000000000000001]> // reports true

This bug occurs because when using this block, Scratch will attempt to check if two quantities are equal either as strings or numbers. Numbers are stored as double-precision floating-point numbers in Scratch, and numbers that cannot be stored (usually because they are too large) are rounded to the nearest storable number, leading to the loss of precision.

This can be solved by adding a letter at the beginning, which forces Scratch to only use a text comparison and not a number comparison:

<(join [a] (100000000000000000)) = (join [a] (100000000000000001))> // reports false

Comparing Text

Text comparisons are not case sensitive. Many believe this is intended to reduce the complexity of the platform and make it easier for young users to understand.

<[a] = [a]> // reports true
<[a] = [A]> // reports true

This can be avoided by making a sprite with one costume with each lowercase letter's name, as well as another, arbitrary name, and use the switch costume to block to check for whether or not a single letter is lowercase, as it is case sensitive.

Workaround

Main article: List of Block Workarounds

The block can be replicated with the following code:

<not < <(a) > (b)> or <(a) < (b) > > >

The following also works:

delete all of [list v]
add (a) to [list v]
if <[list v] contains (b)> then
set [result v] to [true]
else
set [result v] to [false]
end

See Also

References

  1. Scratch 1.3 Source Code: Block Spec ('%n = %n' #b #= #- #-)
  2. topic:101150
Cookies help us deliver our services. By using our services, you agree to our use of cookies.