repeat for each marked card i of this stack - error

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
3d-swiss
Posts: 39
Joined: Thu Nov 06, 2008 9:11 pm

repeat for each marked card i of this stack - error

Post by 3d-swiss » Sat Apr 21, 2012 4:57 pm

Hello

I like to visit all marked cards:
repeat for each marked card i of this stack
-- do something
end repeat
Please tell me, what's the correct first line.

Thanks, have a good weekend.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: repeat for each marked card i of this stack - error

Post by Mark » Sat Apr 21, 2012 5:27 pm

Hi,

Code: Select all

repeat with x = 1 to the number of cards
  if the marked of cd x then
    -- do something
  end if
end repeat
Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: repeat for each marked card i of this stack - error

Post by Dixie » Sat Apr 21, 2012 5:29 pm

Hi...

Code: Select all

on mouseUp
   push card
   
   put the number of marked cards into cardCount
   repeat with count = 1 to cardCount
      go next marked card of this stack
      beep
      wait 1 second
   end repeat
   
   pop card
end mouseUp
be well

Dixie

3d-swiss
Posts: 39
Joined: Thu Nov 06, 2008 9:11 pm

Re: repeat for each marked card i of this stack - error

Post by 3d-swiss » Sat Apr 21, 2012 5:35 pm

Hi,

thanks for the answers. I like the second solution best, because it's faster :-)

BTW: It's confusing, that some objects can be used with 'repeat for each' and other not. :shock:

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: repeat for each marked card i of this stack - error

Post by Mark » Sat Apr 21, 2012 5:50 pm

Hi,

Repeat for each is not for objects but for strings and arrays. Sometimes, strings are in objects, but they're still strings.

Yes, Dixie's script is actually better :-)

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

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

Re: repeat for each marked card i of this stack - error

Post by Klaus » Sat Apr 21, 2012 6:04 pm

Hi guys,
Mark wrote:Repeat for each is not for objects but for strings and arrays.
yep, but I wish this would also work with cards and objects! 8)


Best

Klaus

dochawk
Posts: 43
Joined: Wed Sep 02, 2009 9:29 pm

Re: repeat for each marked card i of this stack - error

Post by dochawk » Thu May 17, 2012 5:02 pm

On the bright side, this thread was easy to find when I was looking for the same answer :)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: repeat for each marked card i of this stack - error

Post by dunbarx » Thu May 17, 2012 6:24 pm

A variation of the two perfectly good scripts you already have, but a little more compact.

repeat with y = 1 to the number of marked cards
set the yourProperty of btn "yourButton" of marked card y to newProperty -- just doing something on each marked card
end repeat

After all these, you should be more comfortable with both marked cards and repeat loops.

Craig Newman

Post Reply