安慰#
介紹#
VEXcode 控制台顯示在 VEXcode 的監視器視窗中。控制台方法可以在專案執行時顯示文字、數字和變數值。它們還可以清除控制台、設定更改顏色後列印的文字顏色,以及監視 VEXcode 監視器標籤中的變數或感測器值。
使用 VS Code 時,基於文字的控制台輸出會顯示在終端機中,而不是 VEXcode 控制台標籤中。
以下是所有方法的清單:
操作-輸出文字或清空控制台。
Getter 方法-讀取使用者輸入。
input— 等待使用者輸入並以文字形式回傳回應。
Mutator — 格式化列印文字。
set_console_text_color— 設定控制台中列印的文字的顏色。
行動#
print#
print 在控制台中顯示文字、數字或變數值。在 VS Code 中, print 在終端機中顯示輸出。
如果您希望列印訊息中包含項目中的值(例如分數、計時器或感測器讀數),請使用自訂字串格式。有關更多信息,請參閱字串格式頁面。
預設情況下,每個 brain.print() 語句都以 \n。這會在列印值後將遊標移至下一行。可選的 end 參數用於更改列印值之後新增的內容。
Usage:
brain.print(value, end=“\n”)
參數 |
描述 |
|---|---|
|
若要在控制台或終端機中顯示的文字、數字或變數值。 |
|
可選。在 |
# Display two messages on separate lines
brain.print("Hello, CTE!")
brain.print("This prints on the next line.")

# Display two messages on the same line
brain.print("Hello,", end=" ")
brain.print("CTE!")

# Print three colors on one line, separated by commas
colors = ["Red", "Green", "Blue"]
for color in colors:
brain.print(color, end=", ")

new_line#
new_line 將遊標移到控制台中下一行的第 1 列。下一個列印的值將顯示在該行。
當您希望下一個列印值從新的一行開始時,請使用此方法。如果未使用此方法,且前 brain.print() 語句使用了 end=“” 或其他不包含 \n\n的值,則下一個列印值將緊跟在同一行的前一個值之後。
Usage:
brain.new_line()
參數 |
描述 |
|---|---|
此方法沒有參數。 |
# Print on two lines
brain.print("Row 1", end="")
brain.new_line()
brain.print("Row 2")

clear#
clear 清除控制台中的所有行。
Usage:
brain.clear()
參數 |
描述 |
|---|---|
此方法沒有參數。 |
# Display text, then clear it after two seconds
brain.print("This will disappear...")
wait(2, SECONDS)
brain.clear()
Getter#
input#
input 顯示可選的提示訊息,等待使用者輸入回應,然後將該回應作為文字傳回。
項目會在執行到 input() 時暫停,直到在控制台中輸入回應。在 VS Code 中,回應會輸入到終端機中。
input() 是文本。要将响应用作数字,请先使用 int() 或 float()。
Usage:
input(prompt)
範圍 |
描述 |
|---|---|
|
可選。在等待回應之前,要在控制台或終端機中顯示的字串。如果未指定提示符,則在等待之前不顯示任何訊息。 |
# Ask for a name, then print a greeting
answer = input("What's your name?")
brain.print("Hello, " + answer)

# Ask for a number, then use it in math
answer = input("Enter a number:")
number = float(answer)
brain.print(number + 1)

變異體#
set_print_color#
set_print_color 設定使用此方法後控制台中列印的文字顏色。在專案開始時,控制台文字顏色設定為 BLACK。
此方法可變更 VEXcode 控制台中的文字顏色。在 VS Code 中,不同終端對顏色的支援可能有所不同。
Usage:
brain.set_print_color(color)
參數 |
描述 |
|---|---|
|
控制台列印文字的顏色:
|
# Print text in different colors
brain.print("Default text color")
brain.new_line()
brain.set_print_color(RED)
brain.print("Red text color")
