global variable change in substack not available to main stack

Ian McKnight iangmcknight at gmail.com
Sun Jul 10 02:23:26 EDT 2011


Hi

I just recreated you scripts in a stack.

Stephen Barncard is correct the more usual place to put the global statement
is outside the handlers at the top of the script.

However. Your original card script is incomplete since the 'put' statement
needs to be put into a handler.

eg
global gBgColor

on openstack -- or preOpenStack or whatever
   put 0, 0, 0 into gBgColor
end openstack

When I made this change the gBgColor reflects changes made in the mousedown
script.


BTW I know that it works the way you have it but when using colour info like
0,0,0 I would recommend putting it into quotes "0,0,0"

HTH

On 10 July 2011 07:02, Slava Paperno <slava at lexiconbridge.com> wrote:

> In openCard script of the main stack:
>
> global gBgColor
> put 0, 0, 0 into gBgColor
>
>
> In a button script in a substack:
>
> on mouseUp
>        global gBgColor
>
>        answer color with gBgColor --white is selected
>        put it into gBgColor
>
>        put gBgColor & cr after msg
>        --255, 255, 255
> end mouseUp
>
> In the Variables panel below script editor (after it is refreshed),
> gBgColor
> is shown to be 0, 0, 0.
>
> In the Message box:
>
> put gBgColor
> --0, 0, 0
>
>
> In other words, the change to a global variable that is made in a substack
> is not available to the global variable of the same name in a script in the
> main stack.
>
> Just last week I carefully followed the discussion of the use of global
> variables (and even participated a little by quoting the User Guide on the
> availability of globals to all substacks), but now I see the same problem
> that was reported by the original poster.
>
> Is it just me now? Or is it the late hour?
>
> Slava
>
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



-- 
Regards


Ian McKnight

iangmcknight at gmail.com
=======================



More information about the use-livecode mailing list