Skip to the article
NeuraCoreUser Wiki
โ† Back to this chapter
Embedded Python

Scripts that do something useful

Three complete scripts, each short enough to read in one go and each doing a real job.

Greet whoever comes in, once each

A shop keeper that says hello to each new arrival and does not repeat itself.

import time

greeted = set()

for minute in range(10):
    for person in avatar.get_nearby_avatars():
        if person["id"] in greeted or not person["name"]:
            continue
        greeted.add(person["id"])
        avatar.send_im(person["id"], "Hello, and welcome to the shop.")
    time.sleep(60)
  • greeted is a set, which is a collection that refuses duplicates. It is what stops the same person being greeted twice.
  • The inner loop looks at everyone currently nearby; the outer one repeats that for ten minutes.
  • Somebody with no name yet is skipped rather than greeted as nobody. They will have one next time round.
  • Sending an instant message needs send_im to be allowed in Action Permissions.

Send an avatar out on a recorded route

Patrol routes are recorded by walking them yourself, in the Patrol tab. A script can start one by name.

routes = avatar.get_patrols()
print(routes)

for route in routes:
    if route["name"] == "Garden round":
        avatar.play_patrol(patrol=route["id"], loop=True)
        break
  • get_patrols answers a list of the routes this avatar has, each with an id and the name you gave it.
  • Printing the list first is how you learn what the names actually are.
  • loop=True keeps it going round until something stops it.
  • Recording routes needs an Individual licence for one per avatar, or Business for a hundred. Playing one is not limited.

Check what this installation is licensed for

Useful at the top of any script you intend to leave running, and the only honest way to find out how much time a seat has left.

licence = avatar.get_licence_state()

print(licence["tier"])
print(licence["licensed"])

for slot in licence["slots"]:
    print(slot["slot_index"], slot["avatar_name"], slot["individual_days"])
  • tier is the licence in force: Free, Individual, Business, or one of the states that means it could not be resolved.
  • licensed is true only when avatars may actually connect.
  • Each slot is a seat, with the avatar on it and the days remaining. Slot 0 is the licence holder and carries no time.
  • This reads and can change nothing. Granting or extending a licence is not something a script may do, deliberately.