So far not a fan...

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

bigal60
Posts: 10
Joined: Tue Jul 28, 2015 3:49 pm

So far not a fan...

Post by bigal60 » Tue Jul 28, 2015 9:35 pm

I'm not quite a fan just yet. I simply declared and initialized a global at the main stack:

global deckImg
put 1062 into deckImg


There is no value in the global in my mouse handler....

Regards.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9738
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: So far not a fan...

Post by dunbarx » Tue Jul 28, 2015 10:02 pm

Al?

If I copy your two-liner verbatim into a button script and run it, nothing bad happens. And then if I go to the message box and invoke this:

Code: Select all

answer deckimg
I get "1062".

So the global was declared and remembered. Yay. Not sure what you are seeing.
All you really need, I will wager, is a bit more practice. And patience. Perhaps you might post your handler. I hope you will be a fan one day soon.

Craig newma

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

Re: So far not a fan...

Post by Simon » Tue Jul 28, 2015 10:10 pm

hmmmm... Gots to know where to look :)
2015-07-28_1408.png
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

bigal60
Posts: 10
Joined: Tue Jul 28, 2015 3:49 pm

Re: So far not a fan...

Post by bigal60 » Tue Jul 28, 2015 10:27 pm

Global declared in my main stack script:

global deckImg
put 1062 into deckImg


code in my Mouse hander:
on mouseUp
answer deckImg
if the icon of me <> the backImg of me then
set the icon of me to the backImg of me
else
set the icon of me to the iconImg of me
end if
end mouseUp


Result:
deckImg

Tried this code in the handler:
answer the deckImg of this stack

Result:

blank screen

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

Re: So far not a fan...

Post by Simon » Tue Jul 28, 2015 10:34 pm

ahhh, you have to declare the variable in the mouseUp code as well.

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

bigal60
Posts: 10
Joined: Tue Jul 28, 2015 3:49 pm

Re: So far not a fan...

Post by bigal60 » Tue Jul 28, 2015 10:36 pm

Say what? A global, is a global, is a global!

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

Re: So far not a fan...

Post by Simon » Tue Jul 28, 2015 10:40 pm

Where you able to find the 1062 in the Variable tab?

And yeah, like the code you wrote first it must be declared in both places.

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

bigal60
Posts: 10
Joined: Tue Jul 28, 2015 3:49 pm

Re: So far not a fan...

Post by bigal60 » Tue Jul 28, 2015 10:43 pm

ok..I changed my handler to this:

on mouseUp
global deckImg
if the icon of me <> deckImg then
set the icon of me to deckImg
else
set the icon of me to the iconImg of me
end if
end mouseUp

my main stack still has:

global deckImg
put 1062 into deckImg

Result:

My button has no image everyother time I toggle it....

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

Re: So far not a fan...

Post by Simon » Tue Jul 28, 2015 11:00 pm

Easier way

Code: Select all

on mouseUp
if the icon of me is 1062 then
set the icon of me to 1063
else
set the icon of me to 1062
end if
end mouseUp
But that may not work with your setup. It would be like a Start/Stop button.

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: 9738
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: So far not a fan...

Post by dunbarx » Tue Jul 28, 2015 11:21 pm

Globals must be declared in every script they are accessed, and ABOVE any handler within that script that uses them. This has cropped up before, from users of other languages, where any declaration at all becomes ubiquitous within the application.

But not in LC.

I am going to submit a feature request on this subject. It has been true for 28 years. I all of a sudden cannot see any advantage to having to do that.

Anyway, LC contains another, far more powerful feature, custom properties. These need only be set once, and thereafter are available anywhere, and survive sessions. They may contain a far greater range of data than globals, and may be accessed within a line, just as globals are. This discussion has also been well traveled...

Klaus
Posts: 13865
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: So far not a fan...

Post by Klaus » Tue Jul 28, 2015 11:55 pm

Hi Al,
my main stack still has:

global deckImg
put 1062 into deckImg
is this inside of a "pre-/openstack" handler?


Best

Klaus

bigal60
Posts: 10
Joined: Tue Jul 28, 2015 3:49 pm

Re: So far not a fan...

Post by bigal60 » Wed Jul 29, 2015 5:44 pm

Hi Klaus, no I defined the global in the Main Stack, no handlers; a true global should not have to be defined in a handler..

Craig, yes it doesn't make sense (to programmers anyway) to have to declare a global again, once declared at the top of the stack. Yes I had defined the image value in a custom property so that the button's original image could be replaced upon toggle...

I finally got this to work yesterday, but for some reason, I had to close and reopen the Stack and it started working.

Thanks guys for your replies.

Regards.

Klaus
Posts: 13865
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: So far not a fan...

Post by Klaus » Wed Jul 29, 2015 5:56 pm

Hi Al,
bigal60 wrote:Hi Klaus, no I defined the global in the Main Stack, no handlers; a true global should not have to be defined in a handler..
AHA! :D

OK, that's why it does not work, this needs to be "triggered" somehow inside of a handler. Put this into the stack script:

Code: Select all

global deckimage

on preopenstack
  put 1063 into deckimage
  ## more preopenstack stuff here, if neccessary...
end preopenstack
Best

Klaus

bigal60
Posts: 10
Joined: Tue Jul 28, 2015 3:49 pm

Re: So far not a fan...

Post by bigal60 » Wed Jul 29, 2015 6:12 pm

Klaus,

This worked, however, I had to close and reopen the Stack before the change would take effect. What's up with that?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9738
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: So far not a fan...

Post by dunbarx » Wed Jul 29, 2015 7:18 pm

owever, I had to close and reopen the Stack before the change would take effect
Are you sure you compiled the script? Or saved the stack, which does the same thing.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”