Create an object in a DIFFERENT card

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: Klaus, FourthWorld, heatherlaine, kevinmiller

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

Create an object in a DIFFERENT card

Post by Weaksafety » Sun Jul 27, 2014 11:01 am

Hi,

I've got a stack with a lot of different cards, each having the same customproperty with a specific value.

I'm trying to write a recursive function, that has to be assigned to a button in a specific card, that does this:
- creates an invisible field in each card
- puts the customproperty into that invisible field
for some cards.

The code I've written does this:

Code: Select all

repeat for each line targetline in the elencoPagine1 of this card   //this is where I stored the list of cards 
      create invisible field "correctTitle" in card targetline
      put the titoloPagina of card targetline into field "correctTitle" of card targetline
   end repeat
As I read from the documentation, "create" only works on the current card, so the script throws an error. Is there any way to get around this without doing it manually?

Many thanks! :D

Mike

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

Re: Create an object in a DIFFERENT card

Post by Klaus » Sun Jul 27, 2014 11:56 am

Hi Mike,

you need to read the whole page of the docs about "create"! :D

This should work:

Code: Select all

...
put the elencoPagine1 of this card into tPages

## We need to "travel" a bit around in the stack for this, so we need to memorize the card we started from:
put the num of this cd into tLastCardNumber
lock screen
  
## Prevent eventiual opencard etc messages for firing!
lock messages
repeat for each line targetline in tPages   //this is where I stored the list of cards 
   go cd targetline
   create invisible field "correctTitle"
   put the titoloPagina of card targetline into field "correctTitle" of card targetline
end repeat
## Go back where we started:
go cd tLastCardNumber
unlock message
unlock screen
...

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

Re: Create an object in a DIFFERENT card

Post by Weaksafety » Sun Jul 27, 2014 1:19 pm

Brilliant Klaus, thanks! I didn't think one could "move" from the current card and still keep a script alive in executing commands, especially if it was placed onto a button in a specific card!

How about those temporary variables? Do I need to declare them at stack level for the script to work? (I suppose not, but it's just to understand a little bit more).

Thanks again!

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

Re: Create an object in a DIFFERENT card

Post by Klaus » Sun Jul 27, 2014 1:38 pm

Hi Mike,
Weaksafety wrote:How about those temporary variables? Do I need to declare them at stack level for the script to work?
if you have "set explicitvariables to true" then you need to declare EVERY variable, local or not!
Otherweise not, since the scope of all used variables stay in the HANDLER, so no problems on other CARDS, if you mean that!


Best

Klaus

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”