Script Error: Unexpected token ,, Line 1,

64 views
Skip to first unread message

Vikon Fighter

unread,
Apr 30, 2015, 8:12:28 AM4/30/15
to androi...@googlegroups.com
I have this script to make a voice-activated NXT, but I'm getting this error: Script Error: Unexpected token ,, Line 1,
This is my code:
//----------------------------\\
// NXT Pet Program \\
//----------------------------\\

// OnStart: Starts the program.
function OnStart() {
    // Create NXT object and connect.
    nxt = app.CreateNxt();
    nxt.ShowDevices();
// Create layout.
CreateLayout();
// Create speech recgognition and set callbacks.
spchrcg = app.CreateSpeechRec();
spchrcg.SetOnReady(function() {
   // Show listening popup.
   app.ShowPopup("Listening...", "Short"); 
});
spchrcg.SetOnResult(function(results) {
   DetermineOutcome(results[0])
});
}

// CreateLayout: Creates the main layout.
function CreateLayout() {
    // Create layout.
lay_main = app.CreateLayout("linear", "VCenter,FillXY");
// Create button.
btn_talk = app.CreateButton("Start Listening", 0.3, 0.1);
btn_talk.SetMargins(0, 0.05, 0, 0);
// Set button callbacks
btn_talk.SetOnTouch(function() {
   // Start recognizing speech.
   spchrcg.Recognize();
});
// Add button to layout.
lay_main.AddChild(btn_talk);
// Add layout to app.
app.AddLayout(lay_main);
}

// DetermineOutcome: Chooses an action from the spoken phrase.
function DetermineOutcome(phrase) {
    if(results[0] == "play") {
        nxt.PlaySoundFile("Woops.rso", 0)
    }
}

Does anyone know why?

Christoph Stehl

unread,
Apr 30, 2015, 2:51:06 PM4/30/15
to androi...@googlegroups.com
Its because the line :

btn_talk.SetOnTouch(function() {
    // Start recognizing speech.
    spchrcg.Recognize();
});

If you cut this and write a normal function then it works:
// Add button to layout.
lay_main.AddChild(btn_talk);
// Set button callbacks
btn_talk.SetOnTouch(btn_talk_OnTouch);
// Add layout to app.
app.AddLayout(lay_main);
}

// DetermineOutcome: Chooses an action from the spoken phrase.
function DetermineOutcome(phrase) {
    if(phrase == "play") {
        nxt.PlaySoundFile("Woops.rso", 0);
    }
}

function btn_talk_OnTouch()

Dave Smart

unread,
May 17, 2015, 5:00:39 AM5/17/15
to androi...@googlegroups.com
Hi Vikon Fighter,

How is your pet coming along?  Can we see a Youtube video of it working yet?

Regards
David
Reply all
Reply to author
Forward
0 new messages