global variable seems to be a part-time global
Posted: Wed Aug 24, 2011 9:30 am
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.