Page 1 of 1

Global Variable Not Working Between Cards?

Posted: Tue Jul 15, 2025 8:30 am
by lucassinner
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

Re: Global Variable Not Working Between Cards?

Posted: Tue Jul 15, 2025 8:57 am
by Klaus
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

Re: Global Variable Not Working Between Cards?

Posted: Tue Jul 15, 2025 1:52 pm
by stam
Agreed - the code should work.
You may want to tick 'show globals' in the script editor to see what value your global is holding.

Re: Global Variable Not Working Between Cards?

Posted: Tue Jul 15, 2025 2:46 pm
by dunbarx
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

Re: Global Variable Not Working Between Cards?

Posted: Wed Jul 16, 2025 8:07 am
by SparkOut
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.

Re: Global Variable Not Working Between Cards?

Posted: Wed Jul 16, 2025 9:37 am
by stam
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

Re: Global Variable Not Working Between Cards?

Posted: Wed Jul 16, 2025 3:30 pm
by dunbarx
All good stuff.

@ lucassinner. What is the latest news?