Script Error: func.apply is not a function

2,563 views
Skip to first unread message

Rocco Cogliano

unread,
Jul 3, 2016, 6:47:33 AM7/3/16
to DroidScript
I don't understand this error.
The error occurs when a function call for the second time . 
The function loops through a list and count the occurrences of certain text strings.

Dave Smart

unread,
Jul 3, 2016, 7:44:31 AM7/3/16
to DroidScript
Hi Rocco,

I think you will have to post some code, so we can see what you are doing.
Message has been deleted

Rocco Cogliano

unread,
Jul 3, 2016, 8:38:27 AM7/3/16
to DroidScript
Hi Dave,
thank you for reply.
I have a list with items that I get with a QR code scan and then the  function loops through list and count the occurrences of certain text strings.
This is the simply code:

function riepilogoListaDispositivi(_lst)
{
                
    /*var marcheAccelerometri = [
                {}
                ];
   
    var modelliDispositivi = [
               {episensor:0, CMG5T:0, a131A_02_3:11, }
               ];
               
          app.Alert(modelliDispositivi[0].a1); */
          
    for (var i=0;;i++)
    {
        var rec = _lst.GetItemByIndex(i);
        if(rec==undefined) break;
        str1=rec.title; //lettura del title degli items
        str2=rec.body; //lettura del body degli items
        
        arr1=str1.split('SN:');
        serial=arr1[1];
        //app.Alert('SN: '+serial);
        
        arr2=arr1[0].split(' ');
        marca = arr2[0];
        modello = arr2[1]
        //app.Alert('Marca: '+marca);
        //app.Alert('Modello: '+modello);
        
        arr3=str2.split(' di ');
        TipoDispositivo=arr3[0];
        arr4=arr3[1].split(' IDdsp:');
        Afferenza=arr4[0];
        IdTipoDispositivo=arr4[1];
        arrNumDispositivi[IdTipoDispositivo-1]++;// conto i vari tipi in lista
    }
    txtRiepilogo = 'In lista sono presenti \n';
    for (i=0;i<11;i++)
    {
        if (arrNumDispositivi[i]>0)
        {
            txtRiepilogo = txtRiepilogo + arrNumDispositivi[i]+ ' ' + nomiTipiDispositivi[i]+'\n';
        }  
    }
    //app.Alert(txtRiepilogo);
    return txtRiepilogo;
}


and this vars in global space:
var i=0;
var arrNumDispositivi = [0,0,0,0,0,0,0,0,0,0,0,0,0,0];
/*
numAccelerometro=0;
numAcquisitore=0;
numAllInOne=0;
numBatteria=0;
numCavo=0;
numGps=0;
numPannello=0;
numRegolatore=0;
numSede=0;
numSismicaAttiva=0;
numVelocimetri=0;
numKit=0;*/

var nomiTipiDispositivi = [     
        'Accelerometri', //0
     'Acquisitori',     //1
     'AllInOne',     //2
     'Batterie',     //3
     'Cavi',     //4
     'Gps',  //5
     'Pannelli',     //6
     'Regolatori',       //7
     '....',             //8
     'Sismica attiva',   //9        
     'Velocimetri',      //10
            'Kit'               //11
            ];

Rocco Cogliano

unread,
Jul 3, 2016, 8:55:23 AM7/3/16
to DroidScript
and this is a screenshot of list where it's possible to see the list items 

Screenshot_2016-07-01-16-06-37 (1).png

Rocco Cogliano

unread,
Jul 7, 2016, 8:28:41 AM7/7/16
to DroidScript
No idea?

Rocco Cogliano

unread,
Jul 7, 2016, 8:28:43 AM7/7/16
to DroidScript
No idea?

Steve Garman

unread,
Jul 7, 2016, 8:31:23 AM7/7/16
to DroidScript
I can't see anything in the code you have posted that accounts for this error.

Are you able to post the whole app, possibly as an spk?

If your app is private, would you be prepared to mail it to me directly?

Rocco Cogliano

unread,
Jul 10, 2016, 7:16:50 PM7/10/16
to DroidScript
Hi Steve,
sorry for my late reply, but I was traveling.
I found error in my code and I solved it. The error due to the fact that a function contained a variable that had the same name of the function. Thanks a lot for your answer and again forgive me for my late response.

Best regards
R

Steve Garman

unread,
Jul 11, 2016, 2:34:23 AM7/11/16
to DroidScript
Thanks for the feedback, Rocco.

It is useful to know a likely cause of that exact message.

Rocco Cogliano

unread,
Jul 11, 2016, 3:20:30 AM7/11/16
to DroidScript
The error results from not explicit declaration of a variable within the function and the variable has the same name as the function .
It is rightly so .

for example:

function OnStart()
{
lay = app.CreateLayout( "linear", "VCenter,FillXY" );
btn = app.CreateButton( "Press Me", 0.3, 0.1 );
lay.AddChild( btn );
//Set function to call when button pressed.
btn.SetOnTouch( f );
//Add layout to app.
app.AddLayout( lay );
}

//Called when user touches our button.
function f()
{
    f=0;         // <============== ERROR
    //var f=0;  // <============== OK
    // g = 0     // <============== OK 
//Show a message.
app.ShowPopup( "Hello World!" );
}


It's my fault.
Beginner's mistake .
= )

Best regards
R

Reply all
Reply to author
Forward
0 new messages