Can't find card in recursive function if card name's default

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
Weaksafety
Posts: 17
Joined: Mon Aug 12, 2013 5:20 pm

Can't find card in recursive function if card name's default

Post by Weaksafety » Wed Jun 18, 2014 10:29 pm

Hiya all,

I've written a recursive function to set a custom property of all cards in my stack. Here's a snippet of the longer function:

Code: Select all

      put the cardnames of this stack into tCardList
      repeat with cardIndex = 1 to the number of lines in tCardList
         put line cardIndex of tCardList into tCard
         if the myPageTitle of card tCard is empty then
            set the myPageTitle of card tCard to "standard"
         end if
      end repeat

Now, it all goes as intended, as long as no card has the default name "card id xxxx". If there's such a card, the following error pops up:

Code: Select all

button "Button": execution error at line xx (Chunk: can't find card), char xx
(xxs are mine as the previous code is just a snippet)
This is a problem for me, as the full function recursively searches substacks as well, so if there's one datagrid template.. Everything stops.

Is there any workaround to this?

Thanks!! :D

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

Re: Can't find card in recursive function if card name's def

Post by Klaus » Wed Jun 18, 2014 10:59 pm

Hi Weaksafety,
Is there any workaround to this?
sure, don't use card NAMES but card NUMBERS :D

Code: Select all

...
## put the cardnames of this stack into tCardList
repeat with tCard = 1 to the number of cards
   ## put line cardIndex of tCardList into tCard
   if the myPageTitle of card tCard = empty then
     set the myPageTitle of card tCard to "standard"
  end if
end repeat
...
Best

Klaus

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

Re: Can't find card in recursive function if card name's def

Post by Simon » Wed Jun 18, 2014 11:17 pm

Woweee that was Fun!
Just drop "card":

Code: Select all

 put the cardnames of this stack into tCardList
      repeat with cardIndex = 1 to the number of lines in tCardList
         put line cardIndex of tCardList into tCard
         if the myPageTitle of tCard is empty then--dropped here
            set the myPageTitle of tCard to "standard"--dropped here
         end if
      end repeat
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

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

Re: Can't find card in recursive function if card name's def

Post by Klaus » Thu Jun 19, 2014 1:23 pm

Hi Simon,

yes, big fun, your script will throw an error at line "if the myTitle..." 8)
Remember that most of his cards have names, only some do not!


Best

Klaus

Weaksafety
Posts: 17
Joined: Mon Aug 12, 2013 5:20 pm

Re: Can't find card in recursive function if card name's def

Post by Weaksafety » Thu Jun 19, 2014 7:43 pm

Thanks a lot to both!
I just modified my script with Klaus' suggestion and it worked like a charm :D

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”