安慰#
介绍#
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=“” 或其他不包含 `end=”\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")
