Repeat loops in closeStack?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Repeat loops in closeStack?

Post by bogs » Thu Feb 28, 2019 3:53 pm

I was spending some time on the text editor today, and decided that I would create a loop that would be fired in the 'closeStack' handler that would close all the cards in the stack after finding out if the user wanted to save any of their contents.

Code: Select all

on closeStack
   if field "textEditor" is not "" or the number of cards of this stack > 1 then
      answer "Would you like to save your work?" with "No" or "Yes"
      if it is "Yes" then 
         saveDocs
      else
         put the number of cards of this stack into tmpNum
         repeat with x=tmpNum down to 0
            close card tmpNum
            if the number of this card is "1" then put "" into field "textEditor"; put "" into field "saved"; put "" into field "filePath"
         end repeat
      end if
   end if
   pass closeStack
end closeStack
I think my mind is not right again, because when it gets to the line "close card tmpNum", it jumps out of the repeat loop (there is 2 cards in the stack while running) and goes back to beginning of the closeStack handler.

I thought unless you coded an exit to a repeat, that wouldn't/couldn't happen?

At first, i thought it was because of a 'preOpenCard' handler I was testing, but I commented that out and it still happens. Any thoughts?
Image

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

Re: Repeat loops in closeStack?

Post by Klaus » Thu Feb 28, 2019 4:00 pm

You cannot close a card, just a stack!
Maybe that confuses the engine?

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Repeat loops in closeStack?

Post by bogs » Thu Feb 28, 2019 4:55 pm

Hm, I think it is this message that is confusing me then -
closeCard

So you can 'delete' a card, but not 'close' it per se. Interesting to know :D
Image

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

Re: Repeat loops in closeStack?

Post by Klaus » Thu Feb 28, 2019 5:20 pm

Yep!

Hint:
When it comes to this line:
...
if the number of this card is "1" then put
...
The current card might NOT be 1!
If you really delete all the cards you better check:
...
if the num of cds = 1 then
...
And if you really
...
if XXX then put "" into field "textEditor"; put "" into field "saved"; put "" into field "filePath"
...
These infos will be lost when closing the stack unless you save the stack.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Repeat loops in closeStack?

Post by dunbarx » Thu Feb 28, 2019 5:48 pm

Bogs.

Think about it. How would you close a card? You can navigate to another card, or if your stack contains only one card, you can close the stack. But one card among many in a stack is pretty immune to that sort of thinking.

Craig

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Repeat loops in closeStack?

Post by bogs » Thu Feb 28, 2019 8:56 pm

I am still green enough in some (many) ways (in this language) that it seemed to make sense to me. Want to hear the strangest part of it? Up until I was running the debugger though that loop, it had seemed to be working :?

I figured if you could 'open' a card, you should be able to (like so much of the language) close it again. And of course, there is that 'closeCard' message, which is what really started the whole thing. If there is a message triggered by closing cards, to my way of thinking, then there must be a way to 'close this card' in order to send it, at least, again, that was the mode I was thinking in.

I am sure I will continue to find every odd instance out in this language. My goal is to reach them all :twisted:
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Repeat loops in closeStack?

Post by dunbarx » Thu Feb 28, 2019 9:23 pm

Bogs.
I figured if you could 'open' a card,
Nope. No such command. Same issue I spoke to. You can navigate to a card (or a stack, which navigates to the first card).

And "opening" a card does indeed send an "openCard" message.

This is likely all just a semantic glitch.

Craig

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Repeat loops in closeStack?

Post by bogs » Thu Feb 28, 2019 9:52 pm

I'll buy that :wink:
Image

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

Re: Repeat loops in closeStack?

Post by Klaus » Thu Feb 28, 2019 10:10 pm

"open" (stack/card) is just a synonym for "go".

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Repeat loops in closeStack?

Post by bogs » Thu Feb 28, 2019 10:16 pm

Yah, but (I think*) you see what I'm saying :wink:
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Repeat loops in closeStack?

Post by dunbarx » Thu Feb 28, 2019 11:31 pm

Yep, there it is, buried as a synonym in the "go" entry in the dictionary.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”