Skip to content

API calls

Group/User/Room ID

  • group.id(value)
  • user.id(value)
  • room.id(value)

calculates the internal green-go id's to be used in for example channel.

channel.assign[1] = group.id(10)  // assigning group 10 to channel 1

Timers

Timers can be usd to create repeating or delayed events or to measure time.

A timer can be accessed as an indexed property (timer[1]), and are based on a 1 millisecond clock

Creating a repeating a timed event

the below example will start a timer and 1 second after initialization the event will trigger and execute its code, inside the event the timer is re-triggered with a 500ms time and will trigger the event 500ms later again

event timer[1]
  // do your stuff
  timer[1] = 500 // set repeat time to 500 ms
end

timer[1] = 1000 // start first event after 1 second

Creating a single delayed event

the below example will start a timer of 5 seconds, after the 5 seconds the timer event will trigger and execute its code. inside the event the timer is canceled to make it available again

after 5 seconds

event timer[1]
  // do your stuff
  cancel timer[1] // release the timer event
end

timer[1] = 5000 // start event after 5 seconds

Creating 10 times event at 1 second intervals

the below example will start a timer of 1 second, after the initial second the event will trigger. the event checks if counter is 0 if not the counter wil be lowered by one and the timer is re-triggered. if 0 the timer will be canceled.

var counter = 9

event timer[1]
  if counter
    counter = counter - 1
    timer [1] = 1000
  else
    cancel timer[1] // release the timer event
  end
  // do your stuff
end

timer[1] = 1000 // start event after 1 seconds

using dynamically assigned timers

instead of using timers directly, it is possible to have the VM find a free timer and use that

event timer // get a free timer
  // do event
  timer = 100 // use the timer that generated this event
end
timer = 100 // set the last found timer

Script to Script communication

Scripts can communicate between each other (either on the same device or via the green-go network). This function is supported by all devices that can run scripts

communication is send in blocks to destinations. destinations are freely numbered. multiple scripts can receive the same data-block if the same control.receive event is set

Script to script events and api

Events

  • control.receive[index]

to receive packets, an control event needs to be setup by creating a event on control.receive[index] with the index set to the destination number to listen on. multiple control.receive events can be set. using a define for the index can help making it more readable, but is not needed

Api calls

  • control.destination(index)

sets the destination index for the next data. all previously data will be send

  • control.write(value) or control.write(key, value)

data can be written as a single value or as a key / value pair. in case a single value is written, then internally it will assign it the next key (starting with 1).

  • control.read(), control.read(key) control.read(key, defaultValue)

when inside a control.receive[] event, it is possible to get the data out of the data block in multiple ways. with no parameters are given, then the next data item is read. when a key is given, this key is searched in the data block. If found it will return this value. If the key is not found, it will return 0. When a default value is also given to the api, then instead of a 0 value the default value is returned in the case the value is not found in the data block

  • control.read.key() control.read.key(key)

if no parameter is given, then the next key is read. A return of 0 indicates end of the block. If control.read() is following the control.read.key() then it uses the key found by the control.read.key() If a key is given, this key is searched. if non-zero is returned the value is found and can be read by control.read()

script to script examples

talk follower example

the following example will trigger an event when the channel talk of channel 1 changes and sends the channel and its talk status to the control destination control.receive.channel.talk (1)

// sending script

define control.receive.channel.talk  1

event channel.talk[1]
  control.destination(control.receive.channel.talk)
  control.write(1) // write the first item, channel number                              
  control.write(channel.talk[1]) // write the second item. channel state
end

the example below will receive the data blok from the previous script, parse it and set the channel accordingly.

// receiving script

define control.receive.channel.talk  1

event control.receive[control.receive.channel.talk]
  local channel = control.read() // read first item, channel number
  channel.talk[channel] = control.read() // read the second item, channel state and set the channel to this value
end

set audio on remote user

The snippet below contains a function that will take 3 properties and sends this to the destination user.id(user) this destination is specific to the user id, all devices with this user id will be able to receive this message. two key value pairs, for gain and threshold are set in the message

// sending script

function set.remote.audio(user, gain, threshold)
  control.destination(user.id(user))
  control.write(1, gain)
  control.write(2, threshold)
end

The script below will receive all messages that are send to its user.id. if key 1 is sent it will set its gain to its associated value. for key 2 the threshold is set if present

//receiving script

event control.receive[settings.user.id]
  audio.gain = control.read(1, audio.gain) // if no gain was send, then use the current setting (no change)
  audio.threshold = control.read(2, audio.threshold)
end

Networking commands

api

Api calls

network.address(string) network.address(p1, p2, p3, p4) create a integer ip address from a string or 4 values from 0-255

Open Sound Control (OSC)

OSC commands can be send and received by all devices with a direct network connection.

OSC api and events

OSC Api calls

  • osc.open(udpport) This will enable osc and will set the udp port to listen on.
  • osc.close Stops the osc part
  • osc.destination(ipaddress) Sets the ip address
  • osc.destination(ipaddress, udpport) Sets the ip address and udp port to send osc commands to -osc.send(url, parameter1, .....) Send one or more parameters to OSC url. osc-url's start with a /, like "/channel/1". at least one parameter needs to be given, and parameters can be integers and/or strings
  • osc.sender() Returns the ipaddress (as an integer) of the current osc command received (to be used inside the scope of a osc.receive event)
  • osc.sender.port() Returns the udp source port of the current osc command received (to be used inside the scope of a osc.receive event)

OSC events

  • osc.receive[url]

setup a receive event for a osc url. multiple events/url's can be setup

OSC property read

  • osc.read(index)

read parameters by index starting at 1

examples

// receiving osc and setting channel 1 talk state accordingly

osc.open(1000) // start listening for osc udp packets on udp-port 1000

event osc.receive["/channel/1/"]
  if osc.receive[1]
    channel.talk[1] = channel.talk.on
  else
    channel.talk[1] = channel.talk.off
  end
end

// sending an osc message to report the talk state of channel 1

osc.open(8000)
osc.destination("192.168.1.255")

event channel.talk[1]
  osc.send("/channel/1/", channel.talk[1])
end
Back to top