Page 1 of 2

So far not a fan...

Posted: Tue Jul 28, 2015 9:35 pm
by bigal60
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.

Re: So far not a fan...

Posted: Tue Jul 28, 2015 10:02 pm
by dunbarx
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

Re: So far not a fan...

Posted: Tue Jul 28, 2015 10:10 pm
by Simon
hmmmm... Gots to know where to look :)
2015-07-28_1408.png
Simon

Re: So far not a fan...

Posted: Tue Jul 28, 2015 10:27 pm
by bigal60
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

Re: So far not a fan...

Posted: Tue Jul 28, 2015 10:34 pm
by Simon
ahhh, you have to declare the variable in the mouseUp code as well.

Simon

Re: So far not a fan...

Posted: Tue Jul 28, 2015 10:36 pm
by bigal60
Say what? A global, is a global, is a global!

Re: So far not a fan...

Posted: Tue Jul 28, 2015 10:40 pm
by Simon
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

Re: So far not a fan...

Posted: Tue Jul 28, 2015 10:43 pm
by bigal60
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....

Re: So far not a fan...

Posted: Tue Jul 28, 2015 11:00 pm
by Simon
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

Re: So far not a fan...

Posted: Tue Jul 28, 2015 11:21 pm
by dunbarx
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...

Re: So far not a fan...

Posted: Tue Jul 28, 2015 11:55 pm
by Klaus
Hi Al,
my main stack still has:

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


Best

Klaus

Re: So far not a fan...

Posted: Wed Jul 29, 2015 5:44 pm
by bigal60
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.

Re: So far not a fan...

Posted: Wed Jul 29, 2015 5:56 pm
by Klaus
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

Re: So far not a fan...

Posted: Wed Jul 29, 2015 6:12 pm
by bigal60
Klaus,

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

Re: So far not a fan...

Posted: Wed Jul 29, 2015 7:18 pm
by dunbarx
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