DroidScript wiki

(was AndroidScript) unofficial documentation by the community

User Tools

Site Tools


Privacy Policy


Version1.42 is out since December 2nd 2016

Frequently Asked Questions


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


This is an old revision of the document!

Image array

Click part of the image to store a number in a 2d array representing the rectangles of the image.

Click a rectangle multiple times and it will toggle between 1 and 2.

A colour-coded rectangle appears on the image to show what value was in the array before it was updated.

This is intended as a demo of one way to treat an image as a grid.

var cellData=[];
//Called when application is started.
function OnStart()
    //Create a layout with objects vertically centered.
    var lay = app.CreateLayout( "linear", "VCenter,FillXY" );    
    //Create a text label and add it to layout.
    var img = app.CreateImage( null, 0.9, 0.5 );
    lay.AddChild( img );
    var btnSave=app.CreateButton("Save");
    //Add layout to app.    
    app.AddLayout( lay );
function imgOnTouch(ev)
     var row,col,val,x1,y1,x2,y2
     var cellWidth=0.1,cellHeight=0.1;
         row = Math.floor(ev.Y/cellHeight);
         col = Math.floor(ev.X/cellWidth);
         x1 = col*cellWidth;
         y1 = row*cellHeight;
         x2 = x1 + cellWidth;
         y2 = y1 + cellHeight;
         val = getData(row,col);
         if(val < 0)
         else if(val === 0)
         else if(val === 1)
function getData(row,col)
   var ret;
   if (cellData.length < row +1)
      return -1;  // represents unset
   ret = cellData[row][col];
      return -1;
   return ret;
function setData(row,col,value)
   while (cellData.length < row +1)
function btnSaveOnTouch()
    var data = JSON.stringify(cellData);
sample_code/image_array.1443452774.txt.gz · Last modified: 2015/09/28 15:06 by stevegarman