Page 1 of 1

Getting an LC error when trying to talk to Javascript

Posted: Sun Jun 21, 2020 4:28 pm
by Opaquer
Hey guys!

EDIT: Post has been solved - see post #4 for the solution. Leaving this up here in case someone else has an error 859 in future with their LC browser! GL everyone!

So, a little while ago I got started on making an app to help with sudokus, and after a few setbacks, decided to put it on the shelf for a bit. Well, with everything that's happening I decided to take it off the shelf and give it a another shot - hopefully while being more successful than last time!

Basically, I have some JS code that can solve a sudoku very quickly, and I got it all working in JS as far as I can tell (I don't actually know much JS, so I've just been working my way through it trying to get it to work, but when I made it into an .html file and ran it in my browser, it did what it was supposed to). Unfortunately when I then go to get LC to communicate with the code I have, I get an error (see picture below).

I thought I was doing something wrong, so decided to start a new stack with the absolute basics of what I thought was needed to make LC and JS communicate just as a proof of concept. I have a field "HTMLText", which lets me paste in HTMLText to use in the browser, and widget "Browser" (very original name, I know!), a button "Button", and a field "Output" to get the output printed in there. Here's my code:

In my "HTMLText" field, I have this:

Code: Select all

<html><head><script type="text/javascript">
function solve(a)
{
	var b=5;
	var c;
	c=a+b;
	livecode.Test(c);
}
</script></head></html>
In theory what I want it to do is take a number from LC, add b (in this case, 5, though in future tests I may want multiple inputs/outputs), then spit it out into my Output field. Test is the handler I've set up in LC that JS will call out for.

My Button code is as follows:

Code: Select all

on mouseup
   put "" into field "Output"
   set the HTMLText of widget "Browser" to field "HTMLText"
   do "solve(5);" in widget "Browser" 
end mouseup
And finally, my card code

Code: Select all

on Test c
   put c into field "Output"
end Test
I've tried setting the javascriptHandlers through code and through the property inspector of my browser and still end up with the same result.

When I run it, I expect it to come back with 10 in the output field, but I get the error below.

Annoyingly enough, I've had this error before last time I was working on the app, and while I can't remember exactly how I fixed it, I think I changed LC versions and it worked. However that isn't working that time around, so not sure if there's something else I'm missing with it. For reference, I have LC Indy 9.6, LC Community 9.6 dp2 and LC Community 9.5.1. I'm also using a new laptop with Windows 10 on it.

If anyone knows this error or how to fix it, I would appreciate it greatly! I'd like to think that once it's fixed I'll be very close to finishing my app, but you know how programming is - once this gets fixed, there'll probably be another 37 issues I'll need to fix up before I can even find the next lot of bugs in it!

If you guys need any more info or for me to test anything, just let me know!

Many thanks!

Re: Getting an LC error when trying to talk to Javascript

Posted: Sun Jun 21, 2020 5:22 pm
by Thierry
Hi Opaquer,

Code: Select all

on mouseup
   put "" into field "Output"
   set the HTMLText of widget "Browser" to field "HTMLText"
   do "solve(5);" in widget "Browser" 
end mouseup
Out of my head,
I would give some times for the widget to be set.

Code: Select all

on mouseup
   put "" into field "Output"
   set the HTMLText of widget "Browser" to field "HTMLText"
   send "doSolve" to me in 1 seconds -- check for the right time
end mouseup

on doSolve
   do "solve(5);" in widget "Browser" 
end doSolve
or do your widget settings in the openstack, opencard,...

HTH,

Thierry

Re: Getting an LC error when trying to talk to Javascript

Posted: Mon Jun 22, 2020 2:44 am
by Opaquer
Hi Theirry

Thanks for the input and the advice - I didn't give it much time to load everything up before!

I changed the code for the button to what you said and gave it a shot, and unfortunately I still got the same error :(

Re: Getting an LC error when trying to talk to Javascript

Posted: Mon Jun 22, 2020 8:11 am
by Thierry
Opaquer wrote:
Mon Jun 22, 2020 2:44 am
Hi Thierry
Thanks for the input and the advice
I changed the code for the button to what you said and gave it a shot,
and unfortunately I still got the same error :(
Hi Opaquer,

Sorry, don't have other ideas, but feel free to send me your testing stack,
I might look at it...

Regards,

Thierry

Re: Getting an LC error when trying to talk to Javascript

Posted: Mon Jun 22, 2020 4:03 pm
by Opaquer
Hey everyone!

I just wanted to give an update to this topic: Thierry and I had a look through some code, and he did his thing of being absolutely amazing when it comes to LC related things. Turns out in my JS code, I had:

Code: Select all

livecode.Test(c);
when what it should be is

Code: Select all

liveCode.Test(c);
That silly capital! Anyway, I just wanted to post this in case anyone else runs into this problem in the future!

Happy coding everyone!