too many arguments error

i wrote a function and i call it and get error too many arguments : 

function prvShow(YTime, YDate,FontDate,sDate,sTime,sHeart,YHeartR,FontHeartR,XHeart,YHeart,FontHeart)//11 arguments
{
dc.setColor(Graphics.COLOR_WHITE,Graphics.COLOR_BLACK);
dc.drawText(dc.getWidth()/2, dc.getHeight()/YTime, FontDate,sTime, Graphics.TEXT_JUSTIFY_CENTER);
dc.drawText(dc.getWidth()/2, YDate, FontDate,sTime, Graphics.TEXT_JUSTIFY_CENTER);

dc.setColor(Graphics.COLOR_GREEN,Graphics.COLOR_BLACK);
dc.drawText(dc.getWidth()/2,YHeartR, FontDate,sHeart, Graphics.TEXT_JUSTIFY_CENTER);

dc.setColor(Graphics.COLOR_RED,Graphics.COLOR_BLACK);
dc.drawText(XHeart,YHeart, FontHeart,"0", Graphics.TEXT_JUSTIFY_RIGHT);
return true;
}

 prvShow(16, 250,customFont2,timeString2,timeString,heartRateText,140,customFont2,350,155,customFont);/11 arguments

  • Hi mate, 

    For sure we are limited to 9 (or 10) arguments, 

    What you can do is to use chart like for exemple 

    prvShow([16, 250] ,customFont2,[timeString2,timeString] ,heartRateText,140,customFont2,[350,155] ,customFont);

  • let's say you have

    myFun(p1,p2,p3,p4,p5,p6.p7,p8.p9,p10)

    You'll get the error. the simplest way to avoid the error is pass an array instead:

    myFun([p1,p2,p3,p4,p5,p6.p7,p8.p9,p10])

    But, do you really want to pass so much?  When the function runs, there are local copies of all the parameters (more memory)

    you may consider doing something like

    var p1,p2,p3,p4,p5,p6,p7;  //things global in your class like say a custom font loaded in a different function

    .

    .

    myFun(p8,p9,p10);  //things that aren't global to the class.