ഇവന്റുകൾ#

ആമുഖം#

ഇവന്റുകൾ നിങ്ങളെ ഫംഗ്ഷനുകൾ സമാന്തരമായി പ്രവർത്തിപ്പിക്കാൻ അനുവദിക്കുന്നു. തുടർച്ചയായി ഫംഗ്ഷനുകൾ വിളിക്കുന്നതിനുപകരം, നിങ്ങൾക്ക് ഒരു ഇവന്റിലേക്ക് ഒന്നിലധികം ഫംഗ്ഷനുകൾ രജിസ്റ്റർ ചെയ്യാനും അവയെല്ലാം ഒരേസമയം ട്രിഗർ ചെയ്യാനും കഴിയും. രജിസ്റ്റർ ചെയ്ത ഓരോ ഫംഗ്ഷനും അതിന്റേതായ ത്രെഡിൽ പ്രവർത്തിക്കുന്നു, ഇത് നിങ്ങളുടെ റോബോട്ടിനെ ഒരേസമയം ഒന്നിലധികം ജോലികൾ ചെയ്യാൻ പ്രാപ്തമാക്കുന്നു - ഡ്രൈവ് ചെയ്യുമ്പോൾ സ്ക്രീനിൽ മൂല്യങ്ങൾ പ്രദർശിപ്പിക്കുന്നത് പോലെ.

ഒരു ഇവന്റ് സൃഷ്ടിക്കുന്നതിനും ഉപയോഗിക്കുന്നതിനും, ഈ ഘട്ടങ്ങൾ ക്രമത്തിൽ പാലിക്കുക:

  1. Event ഉപയോഗിച്ച് ഇവന്റ് സൃഷ്ടിക്കുക.

  2. Event പ്രക്ഷേപണം ചെയ്യുമ്പോൾ, ഫംഗ്ഷൻ ഒരു ആർഗ്യുമെന്റായി നൽകി event ഒബ്ജക്റ്റ് വിളിച്ചുകൊണ്ട് ട്രിഗർ ചെയ്യുന്നതിനായി ഒരു ഫംഗ്ഷൻ രജിസ്റ്റർ ചെയ്യുക.

  3. Broadcast an Event:

    • broadcast – ഒരു ഇവന്റ് ഒബ്‌ജക്റ്റിലെ എല്ലാ രജിസ്റ്റർ ചെയ്ത ഫംഗ്ഷനുകളും ഒരേസമയം പ്രവർത്തിപ്പിക്കാൻ ട്രിഗർ ചെയ്യുന്നു.

    • broadcast_and_wait – ഒരു ഇവന്റ് ഒബ്‌ജക്റ്റിലെ എല്ലാ രജിസ്റ്റർ ചെയ്ത ഫംഗ്ഷനുകളും ട്രിഗർ ചെയ്യുകയും തുടരുന്നതിന് മുമ്പ് അവ പൂർത്തിയാകുന്നതുവരെ കാത്തിരിക്കുകയും ചെയ്യുന്നു.

ഒരു ഇവന്റ് സൃഷ്ടിക്കുക#

Event പ്രത്യേക ത്രെഡുകളിൽ ഫംഗ്ഷൻ എക്സിക്യൂഷൻ കൈകാര്യം ചെയ്യുന്ന ഒരു ഇവന്റ് ഒബ്ജക്റ്റ് സൃഷ്ടിക്കുന്നു.

Usage:
Event()

പാരാമീറ്ററുകൾ

വിവരണം

ഈ കൺസ്ട്രക്റ്ററിന് പാരാമീറ്ററുകൾ ഇല്ല.

# Build Used: Super Code Base 2.0
def move_square():
    for index in range(4):
        drivetrain.drive_for(FORWARD, 150)
        drivetrain.turn_for(RIGHT, 90)

def main():
    # Creating the move_event Event
    move_event = Event()
    move_event(move_square)
    move_event.broadcast()
    bumper.set_color(GREEN)

# Start threads — Do not delete
start_thread(main)

ഒരു ഇവന്റിലേക്ക് പ്രവർത്തനങ്ങൾ രജിസ്റ്റർ ചെയ്യുക#

ഒരു ഇവന്റിലേക്ക് ഒരു ഫംഗ്ഷൻ രജിസ്റ്റർ ചെയ്യുമ്പോൾ, ഇവന്റ് പ്രക്ഷേപണം ചെയ്യുമ്പോൾ അത് ഒരു പ്രത്യേക ത്രെഡിൽ എക്സിക്യൂട്ട് ചെയ്യും.

Usage:
event(callback, args)

പാരാമീറ്ററുകൾ

വിവരണം

event

മുമ്പ് സൃഷ്ടിച്ച ഇവന്റ് ഒബ്ജക്റ്റിന്റെ പേര്.

callback

പരിപാടി പ്രക്ഷേപണം ചെയ്യുമ്പോൾ നടപ്പിലാക്കുന്നതിനായി മുമ്പ് നിർവചിക്കപ്പെട്ട ഒരു ഫംഗ്ഷൻ.

args

ഓപ്ഷണൽ. കോൾബാക്ക് ഫംഗ്ഷനിലേക്ക് കൈമാറേണ്ട ഒരു tuple ആർഗ്യുമെന്റുകൾ.

# Build Used: Super Code Base 2.0
def move_square():
    for index in range(4):
        drivetrain.drive_for(FORWARD, 150)
        drivetrain.turn_for(RIGHT, 90)

def main():
    move_event = Event()
    # Register the move_square function to the move_event Event
    move_event(move_square)
    move_event.broadcast()
    bumper.set_color(GREEN)

# Start threads — Do not delete
start_thread(main)

ഒരു ഇവന്റ് പ്രക്ഷേപണം ചെയ്യുക#

broadcast#

broadcast ഒരു ഇവന്റ് ട്രിഗർ ചെയ്യുന്നു, രജിസ്റ്റർ ചെയ്ത എല്ലാ ഫംഗ്ഷനുകളും പ്രത്യേക ത്രെഡുകളിൽ ആരംഭിക്കുന്നു. ഈ രീതി തുടർന്നുള്ള ഏതെങ്കിലും കോഡിന്റെ എക്സിക്യൂഷൻ താൽക്കാലികമായി നിർത്തുന്നില്ല.

Usage:
event.broadcast()

പാരാമീറ്ററുകൾ

വിവരണം

event

മുമ്പ് സൃഷ്ടിച്ച ഇവന്റ് ഒബ്ജക്റ്റിന്റെ പേര്.

# Build Used: Super Code Base 2.0
def move_square():
    for index in range(4):
        drivetrain.drive_for(FORWARD, 150)
        drivetrain.turn_for(RIGHT, 90)

def main():
    move_event = Event()
    move_event(move_square)
    # Broadcasting the move_event Event
    move_event.broadcast()
    bumper.set_color(GREEN)

# Start threads — Do not delete
start_thread(main)

broadcast_and_wait#

broadcast_and_wait ഒരു ഇവന്റ് ആരംഭിക്കുന്നു, പക്ഷേ തുടർന്നുള്ള ഫംഗ്ഷനുകൾ തുടരുന്നതിന് മുമ്പ് രജിസ്റ്റർ ചെയ്ത എല്ലാ ഫംഗ്ഷനുകളും പൂർത്തിയാകുന്നതുവരെ കാത്തിരിക്കുന്നു.

Usage:
event.broadcast_and_wait()

പാരാമീറ്ററുകൾ

വിവരണം

event

മുമ്പ് സൃഷ്ടിച്ച ഇവന്റ് ഒബ്ജക്റ്റിന്റെ പേര്.

# Build Used: Super Code Base 2.0
def move_square():
    for index in range(4):
        drivetrain.drive_for(FORWARD, 150)
        drivetrain.turn_for(RIGHT, 90)

def main():
    # Set up and call the move_square event
    move_event = Event()
    move_event(move_square)
    # Broadcast the move_event Event and wait
    move_event.broadcast_and_wait()
    bumper.set_color(GREEN)

# Start threads — Do not delete
start_thread(main)