From Test-Scratch-Wiki

() = ()
() = ()
类别 运算类积木
形狀 菱形积木

The () = () 积木 is an 运算类积木 and a 菱形积木. The block checks if the first value is equal to the other value. If the values are equal, the block returns true; if not, false. This block is not case-sensitive.

In Scratch 1.3 and before, it only accepted numbers as values.

Example Uses

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

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

  • Pausing a script until a variable reaches a certain amount
當 @greenflag 被點擊
等待直到 <(score) = [10]>
說出 [Good job!]
當 @greenflag 被點擊
詢問 [Was my joke funny?] 並等待
如果 <(詢問的答案) = [yes]> 那麼 
  說出 [Thank you!] (2) 秒
end
  • Checking if boolean values are the same:
當 @greenflag 被點擊
如果 <<滑鼠鍵被按下?> = <碰到 [角色1 v] ?>> 那麼 
  說出 [Either you are clicking and I am on sprite 1, or you are not clicking and I am not on sprite 1.]
end // fast way
如果 <<<滑鼠鍵被按下?> 且 <碰到 [sprite 1 v] ?>> 或 <<<滑鼠鍵被按下?> 或 <碰到 [sprite 1 v] ?>> 不成立>> 那麼 
  說出 [Either you are clicking and I am on sprite 1, or you are not clicking and I am not on sprite 1.]
end // Harder way
  • Comparing different values
如果 <(x座標) = (size)> 那麼 
  說出 [The sprite size and x座標 are equal.] (5) 秒
否則
  說出 [The sprite size and x座標 are not equal.] (5) 秒
end
  • Doing something when there are 0 lives left
當 @greenflag 被點擊
重複無限次 
  如果 <(lives) = [0]> 那麼 
    說出 [uh oh...]
  end
end

应用

Main article: List of Block Workarounds

The block can be replicated with the following code:

<<<(a) > (b)> 或 <(a) < (b)>> 不成立>

The following also works:

刪除第 (全部 v) 項 \( [list v] \)
新增項目 (a) \( [list v] \)
如果 <清單 [list v] 包含 (b) ?> 那麼 
  變數 [result v] 設為 [true]
否則
  變數 [result v] 設為 [false]
end

参见

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