コンソール#
導入#
VEXcode GOコンソールは、VEXcode内のコンソールタブに表示されます。コンソールメソッドを使用すると、プロジェクトの実行中にテキスト、数値、変数値を表示できます。また、コンソールカーソルを新しい行に移動したり、コンソールをクリアしたり、ユーザー入力を読み取ったり、色の変更後に表示されるテキストの色を設定したり、VEXcodeのモニタータブで変数やセンサー値を監視したりすることもできます。
以下にすべてのメソッドの一覧を示します。
アクション — テキストを出力するか、コンソールをクリアします。
ゲッター — ユーザー入力を読み取る。
input— ユーザー入力を待ち、応答をテキストとして返します。
ミューテーター — 印刷テキストの書式設定。
set_print_color— コンソールに表示されるテキストの色を設定します。
モニター — VEXcodeのモニタータブで、プロジェクト中にセンサーまたは変数の値を監視します。
monitor_sensor— モニター タブに 1 つ以上のセンサー値を追加します。monitor_variable— 1 つ以上の定義済み変数をモニター タブに追加します。
行動#
print#
print は、現在のカーソル位置を使用してコンソールにテキスト、数値、または変数値を表示します。
印刷メッセージに、スコア、タイマー、センサーの読み取り値など、プロジェクトの値を含める場合は、カスタム文字列フォーマットを使用します。詳細については、文字列フォーマットページを参照してください。
次の印刷値を新しい行から開始したい場合は、new_line を使用します。
Usage:
console.print(value, precision)
パラメータ |
説明 |
|---|---|
|
コンソールに表示するテキスト、数値、または変数値。 |
|
オプション。数値を印刷する際に表示する小数点以下の桁数を指定します。デフォルトは |
def main():
# Display a message in the Console
console.print("Hello, robot!")
# Start threads — Do not delete
start_thread(main)

def main():
# Display 1/3 with two decimals
console.print(1 / 3, precision=2)
# Start threads — Do not delete
start_thread(main)

new_line#
new_line コンソールの次の行の 1 列目にカーソルを移動します。次に表示される値はその行に表示されます。
次の印刷値を新しい行から開始したい場合は、この方法を使用してください。
Usage:
console.new_line()
パラメータ |
説明 |
|---|---|
このメソッドにはパラメータがありません。 |
def main():
# Print on two lines
console.print("Row 1")
console.new_line()
console.print("Row 2")
# Start threads — Do not delete
start_thread(main)

clear#
clear コンソールからすべての行をクリアします。
Usage:
console.clear()
パラメータ |
説明 |
|---|---|
このメソッドにはパラメータがありません。 |
def main():
# Display text, then clear it after two seconds
console.print("This will disappear...")
wait(2, SECONDS)
console.clear()
# Start threads — Do not delete
start_thread(main)
ゲッター#
input#
input は、ユーザーが応答を入力するのを待ち、その応答をテキストとして返します。
プロジェクトは、コンソールに応答が入力されるまで、 input() で一時停止します。
input() によって返される値は常にテキストです。応答を数値として使用するには、まず int() または float()で変換してください。
Usage:
input()
パラメータ |
説明 |
|---|---|
このメソッドにはパラメータがありません。 |
# Ask for a name, then print a greeting
answer = input("What's your name?")
console.print("Hello, " + answer)
# Ask for a number, then use it in math
answer = input("Enter a number:")
number = float(answer)
console.print(number + 1)
ミューテーター#
set_print_color#
set_print_color このメソッドが使用された後にコンソールに表示されるテキストの色を設定します。プロジェクトの開始時には、コンソールのテキストの色は BLUEに設定されます。
Usage:
console.set_print_color(color)
パラメータ |
説明 |
|---|---|
|
コンソールに表示されるテキストの色:
|
def main():
# Print text in different colors
console.print("Default text color")
console.new_line()
console.set_print_color(RED)
console.print("Red text color")
# Start threads — Do not delete
start_thread(main)

モニター#
monitor_sensor#
monitor_sensor は、VEXcode のモニター タブに 1 つ以上のセンサー値を追加します。これにより、プロジェクトの実行中にセンサー値の変化を監視できます。
各センサー値を文字列として指定してください。
Usage:
monitor_sensor(“sensor”)
monitor_sensor(“sensor1”, “sensor2”)
パラメータ |
説明 |
|---|---|
|
The sensor value to monitor, given as a string. To monitor more than one sensor value, separate each sensor value with a comma. Options include:
|
# Build Used: Super Code Base 2.0
def main():
# Monitor the rotation in the Monitor tab
monitor_sensor("drivetrain.get_rotation")
drivetrain.turn_for(RIGHT, 450)
# Start threads — Do not delete
start_thread(main)
# Build Used: Super Code Base 2.0
def main():
# Monitor the rotation and heading in the Monitor tab
monitor_sensor("drivetrain.get_rotation", "drivetrain.get_heading")
drivetrain.turn_for(RIGHT, 450)
# Start threads — Do not delete
start_thread(main)
monitor_variable#
monitor_variable 、VEXcode のモニター タブに 1 つ以上の定義済み変数を追加します。これにより、プロジェクトの実行中に変数の値の変化を監視できます。
変数を正常に監視するには monitor_variable グローバルである必要があります。各変数名は文字列として指定してください。
Usage:
monitor_variable(“variable”)
monitor_variable(“variable1”, “variable2”)
パラメータ |
説明 |
|---|---|
|
監視対象となる定義済みグローバル変数の名前を文字列で指定します。複数の変数を監視する場合は、各変数名をカンマで区切ってください。 |
# Build Used: Super Code Base 2.0
def main():
# Monitor the amount of loops
global loops
monitor_variable("loops")
# Drive in a square 3 times
for loops in range(12):
drivetrain.turn_for(RIGHT, 90, DEGREES)
drivetrain.drive_for(FORWARD, 150, MM)
# Start threads — Do not delete
start_thread(main)
actions = 0
# Build Used: Super Code Base 2.0
def main():
# Monitor the amount of loops and actions
global loops, actions
monitor_variable("loops", "actions")
# Drive in a square 3 times
for loops in range(12):
drivetrain.turn_for(RIGHT, 90, DEGREES)
drivetrain.drive_for(FORWARD, 150, MM)
actions = actions + 2
# Start threads — Do not delete
start_thread(main)