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

Ten scripts, and which of them run

One avatar can keep ten scripts. Each has a name and a number, each has an output area of its own, and each can be told to start by itself.

Choosing which one you are looking at

The dropdown at the top of the Python Runner lists every script this avatar has. Choosing one shows that script's code and that script's output, and changes nothing else: every other script that is running carries on running, and carries on collecting its own output, while you look at this one.

Add script makes a new one from the template. Delete removes the one on screen and asks first, because the code goes with it and there is nothing to bring it back.

Names and numbers

Each script has a name you choose and a number NeuraCore gives it. The name is for you; the number is what a command and a log line use.

A number is never given to a second script. Delete script 2 and the next one you add is 4, not 2. That is on purpose: numbers that shuffled up after a deletion would make the command to run script 4 start a different script from one day to the next, and nothing would tell you it had.

Start priority

Priority decides the order when several scripts start at the same moment: the lowest number starts first. When only one script is starting it does nothing at all.

They then run alongside one another. Priority is the order they are started in and not a queue, so a script that loops forever does not hold up the ones after it.

Starting by itself

Tick "start it automatically once the avatar is online" and that script starts on its own each time that avatar connects, in priority order with the others that are ticked. It is off to begin with, on every script.

The other half of it is that every running script stops when its avatar goes offline. A script whose avatar has dropped can do nothing but be refused, so leaving it running would fill the execution history with failures nobody asked for.

Running it and stopping it

Run starts the script on screen and Stop ends it. A script that is already running is left alone rather than started a second time, so pressing Run again is safe and simply does nothing.

Stop reaches a script that is waiting and a script that is looping alike: it is interrupted where it stands. If you would rather it finished tidily, have it ask.

import time

while not avatar.stop_requested():
    for person in avatar.get_nearby_avatars():
        print(person["name"])
    time.sleep(30)

print("Asked to stop, so stopping.")
  • stop_requested answers true once somebody has asked this script to stop.
  • Checking it each time round the loop lets the script end at a point you chose rather than wherever it happened to be.
  • A script that never checks is stopped anyway. This only decides where.

Reading the library from a script

A script can see the same list the dropdown shows.

for script in avatar.list_scripts():
    print(script["id"], script["name"], script["priority"], script["running"])
  • Each entry has the script's number, its name, its priority, whether it starts by itself, and whether it is running right now.

One script starting another

A script can start and stop the others, by number or by name.

print(avatar.run_script("Greeter"))
print(avatar.kill_script(2))
  • run_script answers started, or already_running, which is not an error and means what it says.
  • kill_script answers killed, or not_running.
  • Run Script is switched off in Action Permissions to begin with, because starting a script is not one capability but every capability its own lines reach. Turn it on when you want scripts, the AI or an instant message to be able to start one.

Starting one by instant message

The Master can send run followed by a script's number or name, and kill the same way. The avatar answers whether it started it, whether it was already running, whether it stopped it, or whether it was not running.

An authorized resident can do the same, but only for a script whose own "authorized residents may run it by IM" box is ticked. That box is empty to begin with on every script, and it is worth leaving that way for anything you would not hand somebody the keys to: a script is not one action, it is everything its lines do.