Cloned stacks seem to share globals & events

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
tetsuo29
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 103
Joined: Thu Jun 07, 2007 1:30 am

Cloned stacks seem to share globals & events

Post by tetsuo29 » Mon Jan 29, 2018 4:43 pm

Hello,

I've been building a simple count down timer app. Once I got it working like I want, I thought it would be nice to be able to have multiple timers so I added a "File, New" menu and in that handler, put the following code:

Code: Select all

case "New"
    clone stack "Count It Down"
    break
So far, so good. After I build my standalone, I can create new timer instances but, unfortunately, they seem to share global variables and events fired in one stack affects the others. Is there a way to clone a stack and have each stack not share globals or events?

tetsuo29
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 103
Joined: Thu Jun 07, 2007 1:30 am

Re: Cloned stacks seem to share globals & events

Post by tetsuo29 » Mon Jan 29, 2018 6:21 pm

Sorry folks. I should have thought more before posting.

It's just my global variable that I was using as a semaphore that was being shared by all instances of the cloned stacks.

I made it a script local variable instead of a global and now everything is working like it should.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Cloned stacks seem to share globals & events

Post by dunbarx » Mon Jan 29, 2018 8:38 pm

Hi.

Yep, that is how globals roll.

You might include a filter that checks the identity of the topStack, assuming some property in each clone is different, but that may not be as robust as using script locals.

Craig Newman

Post Reply

Return to “Talking LiveCode”