安慰#

介紹#

VEXcode GO 控制台顯示在 VEXcode 的「控制台」標籤中。控制台方法可以在專案執行時顯示文字、數字和變數值。它們還可以將控制台遊標移動到新的一行、清除控制台、讀取用戶輸入、設定更改顏色後列印的文字顏色,以及在 VEXcode 的「監視器」標籤中監視變數或感測器值。

以下是所有方法的清單:

操作-輸出文字或清空控制台。

  • print — 在控制台中顯示文字、數字或變數值。

  • new_line — 將控制台遊標移到下一行的開頭。

  • clear — 清除控制台中的所有行。

Getter 方法-讀取使用者輸入。

  • input — 等待使用者輸入並以文字形式回傳回應。

Mutator — 格式化列印文字。

監控 — 在 VEXcode 的「監控」標籤中,監控專案期間感測器或變數的值。

  • monitor_sensor — 在監視器標籤上新增一個或多個感測器值。

  • monitor_variable — 在「監視器」標籤中新增一個或多個預定義變數。

行動#

print#

print 使用目前遊標位置在控制台中顯示文字、數字或變數值。

如果您希望列印訊息中包含項目中的值(例如分數、計時器或感測器讀數),請使用自訂字串格式。有關更多信息,請參閱字串格式頁面。

當您希望下一個列印值從新的一行開始時,請使用 new_line。

用法:
console.print(value, precision)

參數

描述

value

若要在控制台中顯示的文字、數字或變數值。

precision

可選。列印數字時顯示的小數位數。預設值為 0,因此數字不顯示小數位。

def main():
    # Display a message in the Console
    console.print("Hello, robot!")

# Start threads — Do not delete
start_thread(main)

VEXcode 控制台,顯示控制台和文字「Hello, robot!」。

def main():
    # Display 1/3 with two decimals
    console.print(1 / 3, precision=2)

# Start threads — Do not delete
start_thread(main)

VEXcode 控制台,顯示控制台和文字「0.33」。

new_line#

new_line 將遊標移到控制台中下一行的第 1 列。下一個列印的值將顯示在該行。

當您希望下一個列印值從新的一行開始時,請使用此方法。

用法:
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)

VEXcode 控制台,顯示控制台,第一行顯示文字“第 1 行”,第二行顯示文字“第 2 行”。

clear#

clear 清除控制台中的所有行。

用法:
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)

Getter#

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)

參數

描述

color

控制台列印文字的顏色:

  • BLACK
  • BLUE
  • GREEN
  • RED

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)

VEXcode 控制台,顯示控制台和藍色文字「預設文字顏色」(第一行),紅色文字「紅色文字顏色」(第二行)。

監視器#

monitor_sensor#

monitor_sensor 將一個或多個感測器值新增至 VEXcode 的「監視器」標籤。這樣,您就可以在專案運行時觀察感測器值的變化。

請以字串形式提供每個感測器的值。

Usage:
monitor_sensor(“sensor”)
monitor_sensor(“sensor1”, “sensor2”)

參數

描述

sensor

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:

  • Timer
    • timer.time
  • Drivetrain
    • drivetrain.get_heading
    • drivetrain.get_rotation
    • drivetrain.get_velocity
    • drivetrain.get_yaw
    • drivetrain.get_roll
    • drivetrain.get_pitch
    • drivetrain.get_crashed
    • drivetrain.is_stopped
  • Motor
    • motor.get_position
    • motor.get_velocity
    • motor.get_current
    • motor.is_stopped
    • motor.is_moving
  • Inertial
    • inertial.get_rotation
    • inertial.get_heading
    • inertial.get_yaw
    • inertial.get_roll
    • inertial.get_pitch
    • inertial.get_accelerationX
    • inertial.get_accelerationY
    • inertial.get_accelerationZ
  • Bumper
    • bumper.is_pressed
  • Eye
    • eye.get_color
    • eye.get_hue
    • eye.get_brightness
    • eye.is_object_detected
    • eye.is_color_detected

# 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 的「監視器」標籤。這樣,您就可以在專案運行時監視變數值的變化。

要成功監控 monitor_variable 變數必須是全域變數。請以字串形式提供每個變數名。

Usage:
monitor_variable(“variable”)
monitor_variable(“variable1”, “variable2”)

參數

描述

variable

要監控的預定義全域變數的名稱,以字串形式給出。若要監控多個變量,請用逗號分隔每個變數名稱。

# 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)