====== 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 ); }