DroidScript wiki

(was AndroidScript) unofficial documentation by the community

User Tools

Site Tools


Sidebar

Privacy Policy

News

Version1.42 is out since December 2nd 2016


Frequently Asked Questions


Namespaces

Note for contributors

If you wish to create a new page in the DroidScript wiki, please click on the most appropriate namespace above and follow the notes for contributors there.

Because of spam, it has been necessary to add a CAPTCHA to the registration form and the save option for editing pages. You will not need to prove you are human if you are logged in, so please register.

Please feel free to improve any existing page, as well as adding new pages to increase the sum of public knowledge about DroidScript.

Formatting Syntax

built_in:nxt_setonconnect

SetOnConnect

The SetOnConnect function allows you to set the name of a function that you would like to be called when the NXT has been successfully connected via Bluetooth. The SetOnConnect function allows you to set the name of a function that you would like to be called when the NXT has been successfully connected via Bluetooth. Callback function returns status of connection (true if connection is successful, and false, if connection failed) and caller nxt object.
Do not use SetOnConnected while using SetOnConnect.

nxt.SetOnConnect( myfunc );

Callback function myfunc. Function name changed to OnConnect.

function OnConnect( success, nxtObj ) {}

Example - Connect to NXT

function OnStart()
{
  nxt = app.CreateNxt();
  nxt.SetOnConnect( OnConnect );
  app.SetMenu( "Connect" );
}
 
function OnMenu( name )
{
  if( name == "Connect" )
    nxt.ShowDevices();
}
 
function OnConnect( success, nxt )
{
  app.Alert( "Connected = " + success, "OnConnect" );
}

Example - Connect / Disconnect to NXT

var nxt;
function OnStart()
{
  nxt = app.CreateNxt();
  nxt.SetOnConnect( OnConnect );
  app.SetMenu( "Connect" );
  app.ShowMenu( true );
}
 
function OnMenu( name )
{
  if( name == "Connect" ) {
    nxt.ShowDevices();
  } else if ( name == "Disconnect" )  {
    nxt.Disconnect();
    app.SetMenu( "Connect" );
    app.ShowMenu( true );
  }
}
 
function OnConnect( success, nxt )
{
  if (success) {
    app.Alert( "Connected to: " + nxt.GetBtName(), "OnConnect" );
    app.SetMenu( "Disconnect" );
  } else {
    app.Alert( "Connection to NXT failed", "OnConnect" );
  }
  app.ShowMenu( true );
}
built_in/nxt_setonconnect.txt · Last modified: 2015/03/11 17:26 by madlyr