Passing global array to 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: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
tasdvl9
Posts: 94
Joined: Fri Dec 06, 2013 3:55 am

Passing global array to a different card.

Post by tasdvl9 » Tue Feb 18, 2014 2:51 am

Hello,

I have two cards in my stack. Card1 and Card2

If I have a line of code like this in Card1:
put htmltext of field "company_name" into myData["company_name"]

How would I pass the contents of myData to Card2?

I tried declaring myData globally..
global myData

but the array is empty when I bring up card 2.

Thanks!

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

Re: Passing global array to a different card.

Post by dunbarx » Tue Feb 18, 2014 3:19 am

Hi.

Array variables are treated just like ordinary ones. If declared globally, they are available in any handler where they are declared.

So, what do you mean "pass the contents to Card 2"? The use of "pass" generally indicates that a parameter is sent from one handler to another. In that case, global variables are not required, as they are still alive in the called handler.

But for a later process, Is there a handler in that card that calls for the variable? It can read it if so. Were they declared global in all handlers that need them? There is something wrong with your code somewhere. Write back with what you find.

Craig Newman

tasdvl9
Posts: 94
Joined: Fri Dec 06, 2013 3:55 am

Re: Passing global array to a different card.

Post by tasdvl9 » Tue Feb 18, 2014 3:48 am

Thanks, Craig.

Yes. You were correct. I did in fact have a bug in my code.
When I selected my button I wasn't filling up the array from the previous card.
I knew this was a bad week to try and give up coffee. It's affecting my thought process :)

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

Re: Passing global array to a different card.

Post by Simon » Tue Feb 18, 2014 4:19 am

I'm still all star struck with custom properties

Code: Select all

on mouseUp
   set the htmlText of fld 1 to "<font face="&quote&"Comic Sans MS, cursive"&quote&">Hello</font>" 
   set the cmyData["company_name"] of this stack to fld 1
   set the cmyData["last_name"] of this stack to "Harry"
end mouseUp
Then add this to any card, any object it says the same thing.

Code: Select all

on mouseUp
   answer the cmyData["company_name"] of this stack
end mouseUp
no more declaring "global iMustRememberToAddThisLine"

next new project!
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

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

Re: Passing global array to a different card.

Post by dunbarx » Tue Feb 18, 2014 5:10 am

Simon.

Are you aware of the stuff you can set a custom property to? Much more than just a string. You can have whole stacks in there. Find the threads that deal with this. Custom properties are really big containers.

Craig

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Passing global array to a different card.

Post by Thierry » Tue Feb 18, 2014 6:14 am

tasdvl9 wrote:I tried declaring myData globally..
global myData

but the array is empty when I bring up card 2.
Hi,
You need to declare (re-declare) global myData
in every script you are using myData.
So, in your case 2 times: in card 1 and card 2 scripts.

HTH,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Post Reply