go to top

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

go to top

Post by Nakia » Fri Feb 15, 2013 6:08 am

Hi,

I have a handler that treis to download a file from a FTP server and I want to add the ability for said handler to try the download 3 times.
So I thought I would just log each failure into a local variable and if that number was <= 3 go to the top of the handler.

But no luck, the go top does not seem to work

Code: Select all

if tUpdatedFile = empty then
  add 1 to lRetries
if lRetries <= 3 then
  go to top
answer lRetries
end if 
end if

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: go to top

Post by Simon » Fri Feb 15, 2013 6:52 am

Hi Nakia,
How about:

Code: Select all

repeat 3 
libURLDownloadToFile "ftp://example.org/new_beta",it
if the result = empty then exit repeat
end repeat
Simon
EDIT: I should have pointed out that "if the result = empty" means that the download was successful so stop trying.
Last edited by Simon on Sat Feb 16, 2013 2:22 am, edited 1 time in total.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Klaus
Posts: 14213
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: go to top

Post by Klaus » Fri Feb 15, 2013 12:33 pm

Hi Nakia,

the correct syntax is:
...
exit to top
## Will stop and leave ANY handler and function!
...
exit NameOfHandler
## As Simon said, this will leave the current REPEAT Loop and or handler
## exit mouseup etc...
...

Best

Klaus

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: go to top

Post by shaosean » Sat Feb 16, 2013 6:55 am

There is a slight difference between exit to top and exit handlerName.. Lets say you had the following code in a button

Code: Select all

on mouseUp
  moo
  oink
end mouseUp

on moo
  # do something
  # this is where the exit commands are placeed
  cow
  # do something else
end moo

on oink
  # do more stuff
end oink

on cow
  # more stuffs
end cow
When you click on the button it runs the commands in the following order:
mouseUp
moo
cow
oink

If you place exit moo before the cow line in the moo handler, the commands run in this order:
mouseUp
moo
oink
So you can see that exit handlerName will just leave the current handler back up the message path and continue with any handlers after the one you exited..

If you place exit to top before the cow line in the moo handler, the commands run in this order
mouseUp
moo
All further processing is halted

Klaus
Posts: 14213
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: go to top

Post by Klaus » Sat Feb 16, 2013 3:15 pm

Sean, did you grow up on a farm?

:D :D :D

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: go to top

Post by shaosean » Sun Feb 17, 2013 7:16 am

Nope.. Why do you ask?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: go to top

Post by Simon » Sun Feb 17, 2013 7:47 am

Hi shaosean,
Are you the same shaosean of the SMTP library and externals fame?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: go to top

Post by shaosean » Sun Feb 17, 2013 8:23 am

Not certain about fame, but otherwise, yuppers..

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: go to top

Post by Simon » Sun Feb 17, 2013 8:47 am

Wicked cool!
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: go to top

Post by shaosean » Sun Feb 17, 2013 9:31 am

If you say so, but Klaus is much more famous (and infamous) than me.. ;-)

Klaus
Posts: 14213
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: go to top

Post by Klaus » Sun Feb 17, 2013 11:59 am

shaosean wrote:Nope.. Why do you ask?
Moo, cow, oink?

Just a thought :D :D :D

Post Reply