Running Javascript on Android

The place to discuss anything and everything about running your LiveCode on Android

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
Opaquer
Posts: 235
Joined: Wed Aug 14, 2013 8:24 am

Running Javascript on Android

Post by Opaquer » Thu Feb 20, 2020 12:58 am

Hey everyone

At the moment I'm making Sudoku app, and I found a handy bit of javascript that I'm going to use to solve the sudoku. The problem though is that when I try it out on my computer, it works flawlessly. No issues, nothing. However, when I deploy it to my phone, it doesn't work. It's as if the Javascript code isn't even being run, which is weird, as I've put a few things in the callback from JS to let me know it work (things like setting the text of a field to something specific, which works on computer but not Android). This is the code I've got here:

Code: Select all

on openStack
   set the javascriptHandlers of widget "browser" to "JSresult"
   set the htmltext of widget "browser" to field "HTML"
   wait 1 ticks with messages
end openStack
This sets the htmlText of my browser to the appropriate htmlText (the html text of this page if you're curious https://hewgill.com/sudoku/, from the "<script type="text/javascript">" line (line 37) to line 204). I have made one change as per Hermann's suggestion, which was to add a line "liveCode.JSresult(grid);" above the "return solutions.length;" line. I have the solve method in LC being called by a button, which is this code:

Code: Select all

on SolveJS
   local sudoku4JS, r
   put "[" into sudoku4JS
   repeat with i = 1 to 9
      put "[" into r
      repeat with j = 1 to 9
         put TestCellTracker[i][j] & comma after r
      end repeat
      put "]" into char -1 of r
      put r & comma after sudoku4JS
   end repeat
   put "]" into char -1 of sudoku4JS
   -- call solve_sudoku Javascript function
   -- ends up by calling livecode handler: JSresult
   --   answer exists(widget "Browser")
   --   answer the javascriptHandlers of widget "browser" 
   --   answer the htmlText of widgetBrowser
   do "var g=" & sudoku4JS & ";var r=solve_sudoku(g);" in widget "Browser"
end SolveJS
Finally, this is my JSResult code:

Code: Select all

command JSresult gridR
   put gridR[1][1] &": "& word 5 of the internet date into fld "TestLabel"
   DrawSolution gridR
end JSresult
On computer, the text of field "TestLabel" changes, but on my phone, it doesn't - almost as if it doesn't even get called or to that point? I don't know if there's an error with the code, my implementation, or just JS with Android in general (really hoping it's not the last one :P!)

If you guys have any advice on how I can fix this, that would be appreciated!

Post Reply

Return to “Android Deployment”