Completely deleting substack / stack

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm
Location: USA

Completely deleting substack / stack

Post by shawnblc » Thu Apr 18, 2019 8:10 am

I have a stack with a substack. On the substack I have a button and I want it to delete the substack. I believe I did this about 3 years ago. I guess I need to spend more time with LC :) What am I doing wrong?

Basically I want the substack to show only once during the lifetime of the application.

On the substack I have:

Code: Select all

on mouseUp
      answer "Hello"
      wait 5 milliseconds
      delete stack "testCard"
end mouseUp
On the main stack I have:

Code: Select all

on closeStack
      save stack "mainStack"
end closeStack

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Completely deleting substack / stack

Post by Klaus » Thu Apr 18, 2019 8:50 am

Hi Shawn,

I think LC does not like to delete a stack while a script IN that stack is being executed.
Just like you cannot delete controls with/in their own script(s).

Add a handler in the MAINSTACK thaqt will delete the substack:

Code: Select all

command el_deleto
  delete stack "testCard"
end el_deleto
Then just call this handler in the substack:

Code: Select all

on mouseUp
      answer "Hello"
      wait 5 milliseconds
      del_deleto
end mouseUp
That should do the trick.

Best

Klaus

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm
Location: USA

Re: Completely deleting substack / stack

Post by shawnblc » Thu Apr 18, 2019 2:49 pm

Thanks Klaus, but I'm still having issues.
Attachments
Untitled 1.7z
(1.19 KiB) Downloaded 152 times

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Completely deleting substack / stack

Post by Klaus » Thu Apr 18, 2019 3:05 pm

Hi Shawn,

you need to type a bit more careful:

Code: Select all

on elDeleto
   ## if there is a stack stack "testCard" then
   if there is a stack "testCard" then
      delete stack "testCard"
   end if
...
With this script I got it working:

Code: Select all

on mouseUp
   answer "hello"
   wait 5 milliseconds
   
   ## No script must be running when we remove the stack!
   close this stack
   
   ## we need to add a tiny dealy here, or the script is still considered running and we get an error
   send "elDeleto" to stack "Test" in 1
   
   ## If eldeleto does work, this line will throw an error, since the stack is not present anymore!
   ## close stack "testCard" of stack "Test"
end mouseUp
Best

Klaus

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm
Location: USA

Re: Completely deleting substack / stack

Post by shawnblc » Thu Apr 18, 2019 4:05 pm

Excellent Klaus. Got it working. Thanks.

I need to try and spend an hour or so with LC every day instead of dropping off and not using it for years at a time. :) Every time I go back to LC and tinker, I'm amazed.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”