Global Variable Not Working Between Cards?

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
lucassinner
Posts: 1
Joined: Tue Jul 15, 2025 8:26 am
Contact:

Global Variable Not Working Between Cards?

Post by lucassinner » Tue Jul 15, 2025 8:30 am

Hi all,
I’m new to LiveCode and trying to pass a value from one card to another using a global variable, but it’s not working as expected.
On Card “Home,” I set the global like this:

Code: Select all

global gUserText
put field "InputField" into gUserText
go to card "Details"
Then on Card “Details”:

Code: Select all

global gUserText
put gUserText into field "DisplayField"
But the field on the second card stays blank. No errors, just nothing shows up. Do I need to declare the global differently? Or is `openCard` timing an issue?
Thanks for any help!
Lucas

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

Re: Global Variable Not Working Between Cards?

Post by Klaus » Tue Jul 15, 2025 8:57 am

Hi Lucas,

welcome to the forum!

Could you please post the complete script(s) where you put the text into the global?
Your example here SHOULD work as advertized! 8)

Best

Klaus

stam
Posts: 3061
Joined: Sun Jun 04, 2006 9:39 pm

Re: Global Variable Not Working Between Cards?

Post by stam » Tue Jul 15, 2025 1:52 pm

Agreed - the code should work.
You may want to tick 'show globals' in the script editor to see what value your global is holding.

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

Re: Global Variable Not Working Between Cards?

Post by dunbarx » Tue Jul 15, 2025 2:46 pm

Hi.

What Stam may have meant was to make sure the global was not empty. The scripts themselves are indeed perfectly sound.

You can test this with:

Code: Select all

global gUserText
put field "InputField" into gUserText
answer gUserText
Make sure there is something in that variable.

Craig

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: Global Variable Not Working Between Cards?

Post by SparkOut » Wed Jul 16, 2025 8:07 am

Also check that you don't have a duplicated field on the details card that's obscuring the destination field. It *might* be that your code is fine, but you're not seeing the content because of something in the way.

stam
Posts: 3061
Joined: Sun Jun 04, 2006 9:39 pm

Re: Global Variable Not Working Between Cards?

Post by stam » Wed Jul 16, 2025 9:37 am

dunbarx wrote:
Tue Jul 15, 2025 2:46 pm
You can test this with: <snip>
you don't need code to see if the global is empty or holding unexpected value - global show directly in the script editor, you just need to tick the “show globals” tickbox.

If the global is a string (and not, say, an array) the code posted will work - but simpler still, you could run this in the messageBox at any time to show what value gUserText contains:

Code: Select all

global gUserText ; put gUserText

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

Re: Global Variable Not Working Between Cards?

Post by dunbarx » Wed Jul 16, 2025 3:30 pm

All good stuff.

@ lucassinner. What is the latest news?

Post Reply