(Redirected from () equals () (block))

() = ()
() = ()
Category Operators
Type Boolean

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 long numbers and there is only a small difference between them, the block will still return true. This bug occurs because Scratch stores numbers as 32-bit integers, and large numbers will get rounded off. This can be solved by adding a letter at the end, which turns the integer into a string. An example of this bug can be found in this project. Some Scratchers have suggested to fix it. [2]

Comparing long numbers slightly different. 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 work well for number comparisons within smaller bounds, however, when comparing very large numbers, this block will often report true for numbers that are similar but not the same.

<(100) = (101)> // reports false
<(1000000000000000) = (1000000000000001)> // reports true

Workaround to issue:

<(join (1000000000000000) [a]) = (join (1000000000000001) [a])> // reports false

This works because the issue is only present for number comparisons, not text comparisons, and turning a number into text forces scratch to use the text comparison process, at the cost of a little bit of performance.

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

A workaround to this issue is to make 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 weather 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.