Why won't my very simple stack work in HTML5?

Bringing your stacks to the web

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Why won't my very simple stack work in HTML5?

Post by Klaus » Tue Jan 30, 2024 4:36 pm

Hi Marc,
mbossiere wrote:
Tue Jan 30, 2024 4:20 pm
Thanks Klaus. "Server" indicates HTML5 support, yes?
no, LC server is another branch of Livecode, a CGI server software like PHP etc.

If a command/function is available in HTML5 then html5 is listed under OS, see screenshot:
lc_os.png
Sorry, I mixed this with the "Platforms" info.

Best

Klaus

mbossiere
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Wed Aug 01, 2007 2:15 am
Location: Tucson Arizona US

Re: Why won't my very simple stack work in HTML5?

Post by mbossiere » Tue Jan 30, 2024 6:48 pm

mbossiere wrote:
Tue Jan 30, 2024 4:27 pm
bn wrote:
Tue Jan 30, 2024 1:34 pm
Hi Marc,
I played around with the problem of the user copying a value from the field. I could not get it directly.
A very ugly workaround is to "put" the content of the field.

Code: Select all

on mouseUp
   get secsToMyLongStamp(the secs)
   put it into fld 1
   put it ## puts 'it' into the black area below your stack
end mouseUp
This puts it into the black area below your stack. From there you are able to copy the value.
It is not nice but at least a way to get at the value.
Kind regards
Bernd
I tested locally (local host) so I do not know if that hack works across the network. There are many security precautions in browsers against a lot of stuff.
Thanks. Yes, I agree - it's ugly but this would be fine in some circumstances. I will try it across a network. So the black band acts like Msg box - very handy to know (As I said, I'm new to this type of deployment)
It works well across a network! I think can make something useful from this. Thank you Bernd.
One other question, I'm encountering a new error while compiling this HTML5 regarding "revMacCursors". It seems a stack of this name is "already in memory" [see attached] but 1) I don't know how this is generated and 2) the error pops up twice during the compile process and gives no option except "OK" which is alarming as I wonder if I'm damaging something I need in my LC engine. Anyway, it's a mystery and I'd like to understand how it gets there. It appears even when I "put empty into stacksInUse" before compiling [only 1 of my own stacks is "in use" downstream.
Marc
Attachments
Screen Shot 2024-01-29 at 3.59.42 PM.png
“You do what you do out of your own private passion for the thing itself”
A Dillard (source: https://educheer.com/essays/annie-dillard-s-handed-my-own-life/)

mbossiere
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Wed Aug 01, 2007 2:15 am
Location: Tucson Arizona US

Re: Why won't my very simple stack work in HTML5?

Post by mbossiere » Tue Jan 30, 2024 6:51 pm

https://wildcard.on-rev.com/my/Emscripten/myDate.html
Here is my date tool with workaround
“You do what you do out of your own private passion for the thing itself”
A Dillard (source: https://educheer.com/essays/annie-dillard-s-handed-my-own-life/)

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Why won't my very simple stack work in HTML5?

Post by bn » Tue Jan 30, 2024 11:03 pm

Hi Marc,

I tried your html-stack and that works.

As far as inclusions conflicts are concerned I hear of those conflicts but then I do not build many standalones.

Maybe you could zip your small stack that shows the confilicts, upload it here from the "Attachment" option and we can try to reproduce the error.

Did you manually include the revMacCursors stack or was it on "search for required inclusions..." in the Standalone Application Settings' "General" section?

Kind regards
Bernd

mbossiere
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Wed Aug 01, 2007 2:15 am
Location: Tucson Arizona US

Re: Why won't my very simple stack work in HTML5?

Post by mbossiere » Tue Jan 30, 2024 11:18 pm

bn wrote:
Tue Jan 30, 2024 11:03 pm
Did you manually include the revMacCursors stack or was it on "search for required inclusions..." in the Standalone Application Settings' "General" section?
Kind regards
Bernd
No, that's the strange part.. I didn't include anything (not intentionally anyway) and as I mentioned I made sure the were no stacks "in use) as well.
I'm not even sure what revMacCursors is, or does. Here is my stack:
Attachments
myDate.livecode.zip
(4.9 KiB) Downloaded 30 times
“You do what you do out of your own private passion for the thing itself”
A Dillard (source: https://educheer.com/essays/annie-dillard-s-handed-my-own-life/)

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Why won't my very simple stack work in HTML5?

Post by bn » Tue Jan 30, 2024 11:23 pm

Marc,

If you look at your stack using the Project Browser you will see stack "revMacCursors" attached as a substack. Remove that stack and it should be fine.

Kind regards
Bernd

mbossiere
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Wed Aug 01, 2007 2:15 am
Location: Tucson Arizona US

Re: Why won't my very simple stack work in HTML5?

Post by mbossiere » Wed Jan 31, 2024 5:52 am

bn wrote:
Tue Jan 30, 2024 11:23 pm
If you look at your stack using the Project Browser you will see stack "revMacCursors" attached as a substack. Remove that stack and it should be fine.
Thanks Bernd. So it was. Not sure how I put that in there, but there is was!
“You do what you do out of your own private passion for the thing itself”
A Dillard (source: https://educheer.com/essays/annie-dillard-s-handed-my-own-life/)

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 261
Joined: Sat Aug 16, 2008 9:48 am
Location: Stockholm, Sweden
Contact:

Re: Why won't my very simple stack work in HTML5?

Post by SWEdeAndy » Wed Jan 31, 2024 9:20 pm

mbossiere wrote:
Mon Jan 29, 2024 8:36 pm
I see. Can you suggest another method by which I can "simulate" the clipboard property?

If I can successfully put my result in fld 1 then how can a user collect that result?
Sorry that I'm late to the party, but I bring the javascript workaround for this. You can put this code in your stack script:

Code: Select all

command copyText pText
   if the platform is not "web" then
      set the clipboardData["text"] to pText
   else
      replace "\" with "\\" in pText ## Escape backslashes
      replace quote with ("\" & quote) in pText ## Escape double quotes
      replace cr with "\r" in pText ## Escape linebreaks
      do "navigator.clipboard.writeText(" & quote & pText & quote & ");" as "javascript"
      wait 2 secs with messages ## Let retarded Chrome catch up...
   end if
   
   answer "The text has been copied to the clipboard."
end copyText
Now, instead of (or in parallel with) outputting your value to fld 1, you do

Code: Select all

get secsToMyLongStamp(the secs)
copyText it
My handler does more than you currently need, so you can delete the lines beginning with "replace" if you want. But if you, or anyone, want to be able to put more complex text into the clipboard then you'll need those lines.

The 'if the platform is not "web" then' part is not strictly necessary either, but prevents errors if the handler is invoked in other environments than web deployment.

You can of course also remove or alter the answer dialog that confirms the copy action. I've found it necessary, for my purposes, to add a slight delay ("wait 2 secs with messages") before proceeding with other script actions, especially when using Chrome, to allow the javascript time to execute, but that may depend on the amount of text being copied (it was a big chunk in my project), so that too may be optional. You'll have to test it out.
Andreas Bergendal
Independent app and system developer
WhenInSpace: https://wheninspace.se

mbossiere
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Wed Aug 01, 2007 2:15 am
Location: Tucson Arizona US

Re: Why won't my very simple stack work in HTML5?

Post by mbossiere » Thu Feb 01, 2024 1:36 am

SWEdeAndy wrote:
Wed Jan 31, 2024 9:20 pm

Sorry that I'm late to the party, but I bring the javascript workaround for this. You can put this code in your stack script:

Code: Select all

command copyText pText
   if the platform is not "web" then
      set the clipboardData["text"] to pText
   else
      replace "\" with "\\" in pText ## Escape backslashes
      replace quote with ("\" & quote) in pText ## Escape double quotes
      replace cr with "\r" in pText ## Escape linebreaks
      do "navigator.clipboard.writeText(" & quote & pText & quote & ");" as "javascript"
      wait 2 secs with messages ## Let retarded Chrome catch up...
   end if
   
   answer "The text has been copied to the clipboard."
end copyText
Now, instead of (or in parallel with) outputting your value to fld 1, you do

Code: Select all

get secsToMyLongStamp(the secs)
copyText it
My handler does more than you currently need, so you can delete the lines beginning with "replace" if you want. But if you, or anyone, want to be able to put more complex text into the clipboard then you'll need those lines.

The 'if the platform is not "web" then' part is not strictly necessary either, but prevents errors if the handler is invoked in other environments than web deployment.

You can of course also remove or alter the answer dialog that confirms the copy action. I've found it necessary, for my purposes, to add a slight delay ("wait 2 secs with messages") before proceeding with other script actions, especially when using Chrome, to allow the javascript time to execute, but that may depend on the amount of text being copied (it was a big chunk in my project), so that too may be optional. You'll have to test it out.
Very excited when I saw this! I tried to execute the above, but not sure I did it right. In the LC IDE is works (I get your response from within copyText, "The text has been copied to the clipboard") so I compiled and uploaded the stack, but when I try it there it succeeds to put the date as expected into fld 1 but there is no response from copyText - nor does the formatted date appear in the clipboard. What am I doing wrong?
I'm attaching my modified stack, and the web version is at
https://wildcard.on-rev.com/my/24-01.31 ... yDate.html
Attachments
myDate.livecode.zip
(2.42 KiB) Downloaded 32 times
“You do what you do out of your own private passion for the thing itself”
A Dillard (source: https://educheer.com/essays/annie-dillard-s-handed-my-own-life/)

mbossiere
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Wed Aug 01, 2007 2:15 am
Location: Tucson Arizona US

Re: Why won't my very simple stack work in HTML5?

Post by mbossiere » Thu Feb 01, 2024 5:51 am

SWEdeAndy,
Thanks for your solution. It's quite remarkable, and good to know it's possible. I'd still like to hear your thoughts on why my first attempt with your CopyText didn't work, but when I incorporated the basic elements of CopyText directly into my mouseUp script, I found success. I altered the initiating button script as follows:
on mouseUp
get secsToMyLongStamp(the secs)
put it into fld 1 -- this is just for user to see what's in clipboard
replace "\" with "\\" in it ## Escape backslashes
replace quote with ("\" & quote) in it ## Escape double quotes
replace cr with "\r" in it ## Escape linebreaks
do "navigator.clipboard.writeText(" & quote & it & quote & ");" as "javascript"
wait 2 secs with messages ## Let retarded Chrome catch up...
answer "The text has been copied to the clipboard."
end mouseUp
and by eliminating the call to a separate function, it seems to work! Quite impressive and opens up many ideas for me.
Here is a link to the new one which populates the clipboard correctly:
https://wildcard.on-rev.com/my/24-01.31 ... yDate.html
One mystery: "The text has been copied to the clipboard." does not appear. The script seems to ignore this.
I would also like to know what a "command" is, versus a "function" - I have not written this type of structure before. How does it differ from a "function"?
Marc
“You do what you do out of your own private passion for the thing itself”
A Dillard (source: https://educheer.com/essays/annie-dillard-s-handed-my-own-life/)

mbossiere
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Wed Aug 01, 2007 2:15 am
Location: Tucson Arizona US

Re: Why won't my very simple stack work in HTML5?

Post by mbossiere » Thu Feb 01, 2024 4:45 pm

SWEdeAndy, I'd also be very curious if you have any similar workarounds concerning file I/O (writing to and from local files on a Mac/Linux/Windows etc) -- and/or the ability to accept clipboard data from a user (incoming). File I/O - even just text - would be magic! Marc
“You do what you do out of your own private passion for the thing itself”
A Dillard (source: https://educheer.com/essays/annie-dillard-s-handed-my-own-life/)

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7238
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Why won't my very simple stack work in HTML5?

Post by jacque » Fri Feb 02, 2024 6:02 am

mbossiere wrote:
Thu Feb 01, 2024 5:51 am
I would also like to know what a "command" is, versus a "function" - I have not written this type of structure before. How does it differ from a "function"?
Marc
This may help:
https://hyperactivesw.com/resources/#16 ... 0d43-fedb
The difference is explained near the end of the text.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 261
Joined: Sat Aug 16, 2008 9:48 am
Location: Stockholm, Sweden
Contact:

Re: Why won't my very simple stack work in HTML5?

Post by SWEdeAndy » Fri Feb 02, 2024 8:57 pm

mbossiere wrote:
Thu Feb 01, 2024 5:51 am
Thanks for your solution. It's quite remarkable, and good to know it's possible. I'd still like to hear your thoughts on why my first attempt with your CopyText didn't work
When testing your stack and doing a test deployment from the IDE, it works as expected, including the answer dialog. I'm using LiveCode 10.0.0 dp 7.

When looking at your html code with the browser developer tool however, it seems that you have used LiveCode 9.6.11 for web deployment?
Unfortunately, that is old tech and a dead end in web development with LiveCode. Using LC 10+ is the way to go, as it uses WebAssembly (WASM) as deployment tech which greatly expands the possibilities to run LC stacks almost completely out-of-the-box in the web browser. One significant thing it can use, which the old tech can't, is the wait command. And since my copying code utilises the wait command, that is quite likely the cause of your web deployment failing to execute code after the wait line. I you keep deploying to web with LC9 you must avoid all use of 'wait'.

Why it helped part of the code to function better by moving it directly into the button script I don't know. Might be another LC9 failure. But since the original version, with a separate handler in the stack script, works fine with LC10, I won't investigating that further. I'm afraid I can only really help with LC10 web deployments.
Andreas Bergendal
Independent app and system developer
WhenInSpace: https://wheninspace.se

mbossiere
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Wed Aug 01, 2007 2:15 am
Location: Tucson Arizona US

Re: Why won't my very simple stack work in HTML5?

Post by mbossiere » Sun Feb 04, 2024 3:09 pm

SWEdeAndy wrote:
Fri Feb 02, 2024 8:57 pm

When testing your stack and doing a test deployment from the IDE, it works as expected, including the answer dialog. I'm using LiveCode 10.0.0 dp 7.

When looking at your html code with the browser developer tool however, it seems that you have used LiveCode 9.6.11 for web deployment?
Unfortunately, that is old tech and a dead end in web development with LiveCode. Using LC 10+ is the way to go, as it uses WebAssembly (WASM) as deployment tech which greatly expands the possibilities to run LC stacks almost completely out-of-the-box in the web browser. One significant thing it can use, which the old tech can't, is the wait command. And since my copying code utilises the wait command, that is quite likely the cause of your web deployment failing to execute code after the wait line. I you keep deploying to web with LC9 you must avoid all use of 'wait'.

Why it helped part of the code to function better by moving it directly into the button script I don't know. Might be another LC9 failure. But since the original version, with a separate handler in the stack script, works fine with LC10, I won't investigating that further. I'm afraid I can only really help with LC10 web deployments.
Thank you Andreas. Very helpful yet again. I was indeed using LC9 not LC10 Preview but will make the switch and try these things again and report back. I saw no reason to use LC10 until now as it is still beta but knowing about WASM changes the picture. I'm excited to investigate this.

And thanks Jacqueline - I read your HyperActive thread about about function versus command structures and it does indeed seem to be more a semantic question than technical with minor exceptions. Good to know.

Marc
“You do what you do out of your own private passion for the thing itself”
A Dillard (source: https://educheer.com/essays/annie-dillard-s-handed-my-own-life/)

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 261
Joined: Sat Aug 16, 2008 9:48 am
Location: Stockholm, Sweden
Contact:

Re: Why won't my very simple stack work in HTML5?

Post by SWEdeAndy » Sun Feb 04, 2024 9:25 pm

mbossiere wrote:
Thu Feb 01, 2024 4:45 pm
SWEdeAndy, I'd also be very curious if you have any similar workarounds concerning file I/O (writing to and from local files on a Mac/Linux/Windows etc) -- and/or the ability to accept clipboard data from a user (incoming). File I/O - even just text - would be magic!
These things are much more difficult to do due to security barriers. The browser never has access to local files unless the user allows permission, and that is anyway normally limited to uploading/downloading a file, if I understand correctly. Reading from and writing to a local file the way a desktop standalone can do will probably never be allowed for a browser (for good reasons too).

Accessing the clipboard data should be simpler, one would assume, but that seems to be a tricky business as well. Theoretically, using navigator.clipboard.readText should do it, but there are user permission issues to overcome first. I have spent some time searching for solutions in various web/javascript forums, but I have not yet had any success in getting a LC stack to do it. I'll look into it again another day, as I too would like to find a method to do this.
Andreas Bergendal
Independent app and system developer
WhenInSpace: https://wheninspace.se

Post Reply

Return to “HTML5”