Page 1 of 1

Create an object in a DIFFERENT card

Posted: Sun Jul 27, 2014 11:01 am
by Weaksafety
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

Re: Create an object in a DIFFERENT card

Posted: Sun Jul 27, 2014 11:56 am
by Klaus
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
...

Re: Create an object in a DIFFERENT card

Posted: Sun Jul 27, 2014 1:19 pm
by Weaksafety
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!

Re: Create an object in a DIFFERENT card

Posted: Sun Jul 27, 2014 1:38 pm
by Klaus
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