Link Search Menu Expand Document

Beginner Example - The bare minimum you need to start using arena-py

Let’s start by installing and importing the library

pip3 install arena-py

Ok, now let’s get started!

Replace [host], [realm], and [scene] with your desired ARENA webserver main host, realm, and scene name, respectively.

export MQTTH=[host] # ARENA webserver main host
export REALM=[realm]
export SCENE=[scene]

Import the library

from arena import *

Start the client

arena = Scene()

You can also pass host and scene as arguments, if you don’t want to use environmental variables. These must be keyword arguments:

scene = Scene(host=[host], scene=[scene])

Note: arena-py will always favor environmental variables over arguments.

Define a task

arena-py works by running tasks in an event loop, so we need a main task for our sample program.

def main():

Our first object

Inside main(), lets make a box!

box = Box(object_id="my_box", position=Position(0,4,-2), scale=Scale(2,2,2))

Note the input arguments. The names must match what they will be in the ARENA JSON specification. We don’t have to worry too much about that now, but keep this in mind, as typos will be very bad!

Box is a type of “Object”. See objects.

Position and Scale are what we call “Attributes”. See attributes.

Adding our object to the ARENA

scene.add_object(box)

Start the event loop

Now, outside of main, we will write:

scene.run_once(main)
scene.run_tasks()

Now, go into the scene to see your box!

Appendix

from arena import *

# setup library
scene = Scene(host="arenaxr.org", scene="example")

def main():
    # make a box
    box = Box(object_id="my_box", position=Position(0,4,-2), scale=Scale(2,2,2))
    # add the box
    scene.add_object(box)

# add and start tasks
scene.run_once(main)
scene.run_tasks()