HI,
I'm using the following script to download a file. After the download I move on to other things, How do I modify this script to force LiveCode to wait until the download is completed before doing anything else besides updating a progress bar?
Currently the program moves on to other handlers that are contingent on the download being finished, which it isn't.
Thanks!
Peter
on downloadFile
open stack "MITA_Updater"
repeat until the lockscreen is "false"
unlock screen
end repeat
updateStatus "Downloading the update..."
load URL "http://artsinteractive.org/updates/MITA-1NEW.livecode" with message "downloadDone"
libURLSetStatusCallback "myProgress",the long ID of scrollbar "Progress"
end downloadFile
on myProgress theObject,theStatus
put theStatus into theObject
end myProgress
on downloadDone pUrl, pStatus
put theURL & "MITA-1NEW.livecode" into thisURL
if pStatus = "cached" then
put url pUrl into url ("binfile:" & thisURL)
end if
unload url pUrl
end downloadDone
Waiting for download to complete
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: Waiting for download to complete
Hi Peter,
you can download files either blocking or NON blocking.
Your current method "load" (like LibURLDownloadToFile etc.) are non blocking so you can display a progressbar or something.
If you use the blocking way like:
...
put URL "http://artsinteractive.org/updates/MITA-1NEW.livecode" into url("binfile:yourfilehere.livecode")
if the result <> empty then
## an error occurred
end if
...
Then the script will halt until the download is finished (or until an error occurs
) but you canot have a progressbar this way.
Maybe you can show an animated GIF or something but that's all. So you have the choice
Another option could be to set a global variable "isloading" or whatever, but then you need to check this in every handler/action
that the user might execute while the download is happening. Know what I mean?
Best
Klaus
you can download files either blocking or NON blocking.
Your current method "load" (like LibURLDownloadToFile etc.) are non blocking so you can display a progressbar or something.
If you use the blocking way like:
...
put URL "http://artsinteractive.org/updates/MITA-1NEW.livecode" into url("binfile:yourfilehere.livecode")
if the result <> empty then
## an error occurred
end if
...
Then the script will halt until the download is finished (or until an error occurs

Maybe you can show an animated GIF or something but that's all. So you have the choice

Another option could be to set a global variable "isloading" or whatever, but then you need to check this in every handler/action
that the user might execute while the download is happening. Know what I mean?
Best
Klaus
Re: Waiting for download to complete
Yes, I understand.
I've sort of solved the problem by using a slightly different procedure. I've made my script (a download and file updater) a two-step method: the user downloads the file by clicking a button, then clicks another button to install when the download is complete. Before it was a single-button, which I see is not possible with an active progress bar.
Thanks.
I've sort of solved the problem by using a slightly different procedure. I've made my script (a download and file updater) a two-step method: the user downloads the file by clicking a button, then clicks another button to install when the download is complete. Before it was a single-button, which I see is not possible with an active progress bar.
Thanks.
Re: Waiting for download to complete
Another way to handle it with a single button is to change your script so that nothing else is called until the download completes. You don't show the whole script so I'm not sure what your handler continues to do, but the solution is to put the remainder of the actions into the "downloadDone" handler. That way you can check to see if the download is completed, and if so, call the handler that does whatever should happen next.
Code: Select all
on downloadDone pUrl, pStatus
put theURL & "MITA-1NEW.livecode" into thisURL
if pStatus = "cached" then
put url pUrl into url ("binfile:" & thisURL)
--> DoMyNextThing HERE <--
end if
unload url pUrl
end downloadDone
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com