Turn

Description

The turn() function rotates Gizmo in the specified direction. This function consumes energy to perform the action.

Syntax

success = turn(direction)

Parameters

  • direction: An integer representing the direction to turn. Use the TurnDirectionEnum:
    • 0: Left
    • 1: Right

Return

The function returns a boolean:

  • True if the turn was successful.
  • False if the turn failed (e.g., due to insufficient energy).

Examples

Here's an example of how to use the turn() function:

# Turn Gizmo to the right
success = turn(TurnDirectionEnum.Right)

if success:
    print("Gizmo successfully turned right!")
else:
    print("Gizmo couldn't turn right. There might be insufficient energy.")

# Make Gizmo do a full 360-degree turn
for _ in range(4):
    if turn(TurnDirectionEnum.Left):
        print("Turned left successfully")
    else:
        print("Failed to turn left")
        break

This example demonstrates how to turn Gizmo in a specific direction and how to perform a series of turns.

Notes

  • The turn() function becomes available at level 1 (UnlocksAtLevel: 1).
  • Turning consumes energy. Make sure to check energy levels regularly.
  • Always check the return value to ensure the turn was successful.
  • Combining turn() with move() allows for more complex navigation patterns.