スイッチ#
導入#
Switchブロックは、生徒がブロックベースのコーディングからテキストベースのコーディングへスムーズに移行できるよう支援します。Switchブロックを使用すると、生徒はブロックプロジェクト内でPythonコードを直接入力できます。コマンド、条件、値、関数定義などを記述しながら、プロジェクトの残りの部分はブロックで構築できます。個々のブロックは、対応するPythonコマンドに変換することも可能です。
Python コマンド、メソッド、演算子の入力方法については、VEX V5 Python API を参照してください。
SwitchブロックにはPythonコードが含まれているため、プロジェクトが期待どおりに動作するためには、スペル、句読点、インデントが正しい必要があります。
以下は、すべてのスイッチブロックのリストです。
ブロックの切り替え — ブロックプロジェクトにPythonコードを追加します。
スタック — 他のスタックブロックと順番に実行される Python コマンドを入力するスペースを提供します。
Cブロック —
ifwhileforステートメントなどの Python 制御コードwhile提供します。C Expandable — Provides a space to type Python control code with multiple branches, such as
if,elif, orelse.Boolean —
TrueまたはFalseを返す Python コードを入力するスペースを提供します。レポーター — 値を返すPythonコードを入力するスペースを提供します。
Hat — Python 関数を定義するためのスペースを提供します。
スタック#
スタックブロックは、他のスタックブロックと順番に実行されるPythonコマンドを入力するためのスペースを提供します。
[] :: custom-switch
スタックブロックには、1行または複数行のPythonコードを含めることができます。
開始したとき :: hat events
[Drive forward, then stop.]
[drivetrain.drive(FORWARD)] :: custom-switch
[2] 秒待つ
走行停止
C棟#
The C Block provides a space to type Python control code, such as if, while, or for statements. Blocks placed inside the C Block run as part of that Python control structure.
if [] :: custom-switch
終わり
Cブロックで使用できるPython制御コードには以下が含まれます。
開始したとき :: hat events
[Drive forward when the screen is pressed.]
ずっと
if [if brain.screen.pressing():] :: custom-switch
[前進 v] へ [200] [mm v] 走行 ▶
終わり
終わり
C拡張可能#
The C Expandable block provides a space to type Python control code with multiple branches, such as if, elif, or else. Additional branches can be added by selecting the plus arrow.
if [] :: custom-switch-expand
終わり
C Expandableブロックで使用できるPython制御コードには、以下のものが含まれます。
開始したとき
[Turn right when the screen is pressed, otherwise turn left.]
ずっと
if [if brain.screen.pressing():] :: custom-switch-expand
[右 v] へ旋回
else [else:] :: custom-switch-expand
[左 v] へ旋回
終わり
終わり
ブール値#
ブールブロックは True または Falseを返すPythonコードを入力するスペースを提供します。六角形の入力を持つブロック内に配置できます。
<[] :: custom-switch>
ブールブロックにはPythonの条件を含めることができます。
<[bumper_a.is_pressed()] :: custom-switch>
ブールブロックでは、論理演算子も使用できます。
<[bumper_a.is_pressed() or bumper_b.is_pressed()] :: custom-switch>
ブールブロックでは、比較演算子を使用して値を比較できます。
より大きい:
>未満:
<等しい:
==その他の比較演算子には、
<=、!=、および>=があります。
<[drivetrain.get_heading()> 100] :: custom-switch>
開始したとき :: hat events
[Drive forward whenever the screen is pressed.]
ずっと
もし <[brain.screen.pressing()] :: custom-switch> なら
[前進 v] へ [200] [mm v] 走行 ▶
終わり
終わり
記者#
Reporterブロックは、値を返すPythonコードを入力するスペースを提供します。循環入力を持つブロック内に配置できます。
([] :: custom-switch)
Reporterブロックには、値を返すPythonコードを含めることができます。
([drivetrain.rotation()] :: custom-switch)
Reporterブロックでは、数学演算子を使用できます。
([drivetrain.rotation() + 45] :: custom-switch)
開始したとき :: hat events
[Display the rotation while turning.]
[右 v] へ [450] 度旋回 ◀ 待たない
ずっと
全行をクリア
([drivetrain.rotation()] :: custom-switch) を表示 ▶
[0.1] 秒待つ
終わり
帽子#
ハットブロックは、Python関数を定義するためのスペースを提供します。ハットの下に接続されたブロックは、その関数の本体となります。
[] :: hat custom-switch
ハットブロックにPython関数の定義を入力します。引数は括弧の中に記述します。引数を使用しない関数の場合は、空の括弧を使用します。
[def function_name(parameter):] :: hat custom-switch
[def drive_400():] :: hat custom-switch
[Create a function to drive the robot forward.]
[前進 v] へ (400) [mm v] 走行 ▶
開始したとき :: hat events
[drive_400()] :: custom-switch