tip - Easy way to check if Globals are working

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
sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am

tip - Easy way to check if Globals are working

Post by sphere » Sun Sep 28, 2014 10:09 am

Hello,

i had some troubles to get my globals working.
Maybe you allready know but this is really handy to check if your global is getting there where you need it.

declare the global you need on every script you need

Code: Select all

global gIamHere
put field "WhereAreYou" into gIamHere
then on the script where you need the global

Code: Select all

global gIamHere
answer gIamHere
If your global works you will get a pop-up giving you the answer of the global.

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

Re: tip - Easy way to check if Globals are working

Post by Klaus » Sun Sep 28, 2014 11:57 am

Hi sphere,
sphere wrote:...

Code: Select all

global gIamHere
answer gIamHere
If your global works you will get a pop-up giving you the answer of the global.
well, this will only display the content of the global variable!
So I'm not sure what you mean with "If your global works..."?

Code: Select all

global gIamHere
answer gIamHere
As soon as you DECLARE a global variable it will be created (and will be EMPTY until you fill it with content)
So not sure what you really mean?

You could check for content:

Code: Select all

global gIamHere
if gIamHere = EMTPY then
  answer "Variable gIamHere is EMPTY!"
end if
...
Best

Klaus

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am

Re: tip - Easy way to check if Globals are working

Post by sphere » Sun Sep 28, 2014 12:13 pm

Hi Klaus,

yes sorry that is what i mean.
When the global is filled, then you can see it at the answer.
and thanks for your empty message script, also very useful.

by the way i noticed that the global is not always refreshed.
i am selecting an item from the scrolling list and make it a global variable, this works ok.
but when i select an other item (only one at a time can be selected) then the answer check which we created shows the previous item and not the one i selected now.

any idea why it is not refreshed, or is there a way to empty the global againd after it is used?

Thanks for your help!

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

Re: tip - Easy way to check if Globals are working

Post by Klaus » Sun Sep 28, 2014 12:26 pm

Hi spere,

maybe the global variable is not (correctly) declared?
It must be declard in ANY script that uses it.

Example, a script with more than one handlers:

Code: Select all

## Both handlers in this script can access the global variable!
global gGlobalVariable

on mouseup
  put 10 into gGlobalVariable
end mouseup

command my_command
  add 10 to gGlobalVariable
end my_command
Single handler script, here you can declare the global at the top of the scrip or in the handler directly:

Code: Select all

## Version 1:
global gGlobalVariable

on mouseup
  put 10 into gGlobalVariable
end mouseup

Code: Select all

## Version 2:
on mouseup
  global gGlobalVariable
  put 10 into gGlobalVariable
end mouseup
Make sure your script does in fact declare the global at the correct place (and at all!)

Maybe you can post your script that does not work as exspected?


Best

Klaus

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am

Re: tip - Easy way to check if Globals are working

Post by sphere » Sun Sep 28, 2014 1:13 pm

Hi Klaus

part of scrolling list script:

Code: Select all

global gSendEmail
# select hilited item and make a global variable------------works OK
on mouseUp
   get line (the hilitedLines of field "emaillist") of field "emaillist"
   put it into tSendEmail
   #answer tSendEmail
   put tSendEmail into gSendEmail
   #answer gSendEmail
end mouseUp
and part of the Send button script

Code: Select all

global gSendEmail
on mouseUp
answer gSendEmail
end mouseUp
so the send button has multiple tasks to complete-->renaming of the file and saving to another folder which we solved, and now sending it to an email address Allready found some code to test
so if this works i can continue to the next step

thanks for helping

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

Re: tip - Easy way to check if Globals are working

Post by Klaus » Sun Sep 28, 2014 1:34 pm

Hm, looks OK, so it should work in fact!

but you can save a LOT OF typing in the first script:

Code: Select all

global gSendEmail
on mouseUp
   put line (the hilitedLines of field "emaillist") of field "emaillist" into gSendEmail
end mouseUp
No need to use IT or another variable :D

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am

Re: tip - Easy way to check if Globals are working

Post by sphere » Sun Sep 28, 2014 1:47 pm

ok great i will test your line.
save indeed a lot of typing.

thanks!

Post Reply