安慰#
介绍#
以下是所有方法的列表:
操作——与控制台交互。
print
– Print text to the Console.new_line
– Move the Console cursor position at the start of the next row down.clear
– Clear all text from the Console.
Mutators – 更改控制台中的文本颜色。
set_print_color
– Set the color text will display in for the Console.
监控——在 VEXcode 的监控选项卡中监控项目期间传感器或变量的值。
monitor_sensor
– Add a sensor to the Monitor tab.monitor_variable
– Add a predefined variable to the Monitor tab.
行动#
print#
print
使用当前光标位置在控制台中打印值。
用法:
console.print(value, precision)
参数 |
描述 |
---|---|
|
要打印为字符串或数字的值。 |
|
可选。指定打印的小数位数。默认值为 0。 |
# Build Used: Super Code Base 2.0
def main():
# Display a message in the console
console.print("Hello, robot!")
# Start threads — Do not delete
start_thread(main)
# Build Used: Super Code Base 2.0
def main():
# Print a number with 5 decimals
console.print(math.pi, precision = 5)
# Start threads — Do not delete
start_thread(main)
new_line#
new_line
将光标移动到控制台中当前位置下方的行首。
用法:
console.new_line()
参数 |
描述 |
---|---|
该方法没有参数。 |
# Build Used: Super Code Base 2.0
def main():
# Print on two lines
console.print("Line 1")
console.new_line()
console.print("Line 2")
# Start threads — Do not delete
start_thread(main)
clear#
clear
清除控制台中的所有文本。
用法:
console.clear()
参数 |
描述 |
---|---|
该方法没有参数。 |
# Build Used: Super Code Base 2.0
def main():
# Clear the console after printing
console.print("This will disappear...")
wait(2, SECONDS)
console.clear()
# Start threads — Do not delete
start_thread(main)
修改器#
set_print_color#
set_print_color
设置将文本打印到控制台时使用的颜色。
用法:
set_print_color(color)
参数 |
描述 |
---|---|
|
打印文本的颜色:
|
# Build Used: Super Code Base 2.0
def main():
# Print in different colors
console.print("Default text color")
wait(1, SECONDS)
console.set_print_color(RED)
console.print("Red text")
# Start threads — Do not delete
start_thread(main)
监视器#
monitor_sensor#
monitor_sensor
在 VEXcode 的 Monitor 选项卡中添加要监控的传感器值。
用法:
monitor_sensor(“sensor”)
参数 |
描述 |
---|---|
|
要监控哪个传感器,以字符串形式给出:
|
# 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)
monitor_variable#
monitor_variable
在 VEXcode 的 Monitor 选项卡中添加一个要监控的预定义变量。
用法:
monitor_variable(“variable”)
参数 |
描述 |
---|---|
|
要监视的预定义变量的名称,以字符串形式给出。 |
loops = 0
# Build Used: Super Code Base 2.0
def main():
# Monitor the amount of loops
global loops
monitor_variable("loops")
while loops < 12:
drivetrain.turn_for(RIGHT, 90)
drivetrain.drive_for(FORWARD, 150, MM)
loops += 1
# Start threads — Do not delete
start_thread(main)