global variable seems to be a part-time global
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
global variable seems to be a part-time global
Hi,
I'm having a little problem with a global, but probably have misunderstood globals.
My problem is a stack, say, with one card.
In the stack :
global G
on openstack
put 1 into G
go card "X"
end onopenstack
and in card X
global G
on opencard
answer G
end opencard
When I have made my morning coffee, and start livecode from scratch, and start the stack, card X sees G as empty.
If I use "Close and Remove from memory", and then open the stack again, card X thinks G is 1
If I then quit livecode completely, and restart livecode and open the stack, card X thinks G is empty.
It's behaving as though the stack script is running off to open card X before it has quite finished squeezing 1 into G, and so X doesn't see the global G. Then eventually it seems that G does become 1, but too late for card X. When I remove the stack from memory and reload, G has retained its value anyway so card X can use it.
If I quit livecode and restart, G is again empty when card X opens.
The global does seem to be shared by the stack and card, otherwise the card X would never see 1 in G. My problem seems to be that the card X is getting opened before G gets set.
I'm having a little problem with a global, but probably have misunderstood globals.
My problem is a stack, say, with one card.
In the stack :
global G
on openstack
put 1 into G
go card "X"
end onopenstack
and in card X
global G
on opencard
answer G
end opencard
When I have made my morning coffee, and start livecode from scratch, and start the stack, card X sees G as empty.
If I use "Close and Remove from memory", and then open the stack again, card X thinks G is 1
If I then quit livecode completely, and restart livecode and open the stack, card X thinks G is empty.
It's behaving as though the stack script is running off to open card X before it has quite finished squeezing 1 into G, and so X doesn't see the global G. Then eventually it seems that G does become 1, but too late for card X. When I remove the stack from memory and reload, G has retained its value anyway so card X can use it.
If I quit livecode and restart, G is again empty when card X opens.
The global does seem to be shared by the stack and card, otherwise the card X would never see 1 in G. My problem seems to be that the card X is getting opened before G gets set.
Re: global variable seems to be a part-time global
Hi Kewin,
It work for me (with an old powerbook G4 for the first test)
I see you have a "end onopenstack" instead "end openstack" in your script
It is the same in your stack ?
Best regards from Geneva after tea time
Jean-Marc
It work for me (with an old powerbook G4 for the first test)
I see you have a "end onopenstack" instead "end openstack" in your script
Code: Select all
on openstack
put 1 into G
go card "X"
end onopenstack
Best regards from Geneva after tea time
Jean-Marc
https://alternatic.ch
Re: global variable seems to be a part-time global
Hi Jean-Marc
That's just a typo when I posted the message, the stack script is correct !
Regards
Kevin
That's just a typo when I posted the message, the stack script is correct !
Regards
Kevin
Re: global variable seems to be a part-time global
Hi Kewin,
I tested it and it work
stack script
Card script
Best
Jean-Marc
I tested it and it work
stack script
Code: Select all
global G
on openstack
put 1 into G
go to card "X"
end openstack
Code: Select all
global G
on opencard
answer G
end opencard
Jean-Marc
https://alternatic.ch
Re: global variable seems to be a part-time global
Kevin
Try declaring the global in a 'preOpenStack' handler instead of an 'openStack' handler... I've sometimes seen the same and going down the 'preOpenStack' road seems to solve the problem...
be well,
Dixie
Try declaring the global in a 'preOpenStack' handler instead of an 'openStack' handler... I've sometimes seen the same and going down the 'preOpenStack' road seems to solve the problem...
be well,
Dixie
Re: global variable seems to be a part-time global
Hi,Dixie wrote: Try declaring the global in a 'preOpenStack' handler instead of an 'openStack' handler... I've sometimes seen the same and going down the 'preOpenStack' road seems to solve the problem...
Yes, this solves it, and I think I have found out why.
When you start livecode, it goes to the last card you were on previously (X, say), and then it executes openstack.
If card X is relying on globals set up in openstack, card X fails.
If I do what you suggest, it works. I think what happens is when livecode starts, it executes preopenstack (setting up the globals), then it jumps to the last card that was in use, X, which now works, and then it executes openstack.
So, preopenstack (set globals), display global-needy card X (forced by livecode), openstack is the order that works.
Thank you Dixie
Kevin
Re: global variable seems to be a part-time global
Hi Kewin,
I tested with livecode on an iMac and i have the same result of you. "go to cd x jump the opencad of the first cd"
(the first test was with rev 4.0 on a powerbook)
It work for me if you set the global G to 1 at preopenstack but i think it is better using preopencard in the script of the first cd instead preopenstack
I put a little stack to see the messages history
Best regards
Jean-marc
I tested with livecode on an iMac and i have the same result of you. "go to cd x jump the opencad of the first cd"
(the first test was with rev 4.0 on a powerbook)
It work for me if you set the global G to 1 at preopenstack but i think it is better using preopencard in the script of the first cd instead preopenstack
I put a little stack to see the messages history
Best regards
Jean-marc
- Attachments
-
- HistoryMsg.livecode.zip
- (2.1 KiB) Downloaded 227 times
Last edited by jmburnod on Fri Aug 26, 2011 11:45 am, edited 1 time in total.
https://alternatic.ch
Re: global variable seems to be a part-time global
Hi Jean-Marc,
Thanks for this.
My problem is that my openstack script was trying to set globals by reading a history log, and then going to the correct card.
Livecode was taking me to card X, and then executing openscript, which was too late, because by then card X had failed.
If I use preopenstack, it of course works ok.
I cannot set globals up in the preopen card, as the card is only called as a result of a decision made elsewhere, and has to populate itself according to those globals. If it set up its own globals, it would always populate itself the same way.
Thanks
Kevin
Thanks for this.
My problem is that my openstack script was trying to set globals by reading a history log, and then going to the correct card.
Livecode was taking me to card X, and then executing openscript, which was too late, because by then card X had failed.
If I use preopenstack, it of course works ok.
I cannot set globals up in the preopen card, as the card is only called as a result of a decision made elsewhere, and has to populate itself according to those globals. If it set up its own globals, it would always populate itself the same way.
Thanks
Kevin
Re: global variable seems to be a part-time global
Hi Kewin,
Thank for explanations
my last message contains one error.
I changed it
best
Jean-Marc
Thank for explanations
my last message contains one error.
I changed it
best
Jean-Marc
https://alternatic.ch