So far not a fan...
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
So far not a fan...
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.
global deckImg
put 1062 into deckImg
There is no value in the global in my mouse handler....
Regards.
-
- VIP Livecode Opensource Backer
- Posts: 9738
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: So far not a fan...
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:
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
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
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
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: So far not a fan...
hmmmm... Gots to know where to look
SimonI used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: So far not a fan...
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
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
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: So far not a fan...
ahhh, you have to declare the variable in the mouseUp code as well.
Simon
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: So far not a fan...
Say what? A global, is a global, is a global!
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: So far not a fan...
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
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!
Re: So far not a fan...
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....
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....
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: So far not a fan...
Easier way
But that may not work with your setup. It would be like a Start/Stop button.
Simon
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
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- VIP Livecode Opensource Backer
- Posts: 9738
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: So far not a fan...
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...
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...
Hi Al,
Best
Klaus
is this inside of a "pre-/openstack" handler?my main stack still has:
global deckImg
put 1062 into deckImg
Best
Klaus
Re: So far not a fan...
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.
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...
Hi Al,
OK, that's why it does not work, this needs to be "triggered" somehow inside of a handler. Put this into the stack script:
Best
Klaus
AHA!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..
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
Klaus
Re: So far not a fan...
Klaus,
This worked, however, I had to close and reopen the Stack before the change would take effect. What's up with that?
This worked, however, I had to close and reopen the Stack before the change would take effect. What's up with that?
-
- VIP Livecode Opensource Backer
- Posts: 9738
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: So far not a fan...
Are you sure you compiled the script? Or saved the stack, which does the same thing.owever, I had to close and reopen the Stack before the change would take effect
Craig