My preopenstack handler missing something

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

oldummy
Posts: 79
Joined: Mon Jun 13, 2016 3:21 pm

My preopenstack handler missing something

Post by oldummy » Fri Dec 15, 2023 7:47 pm

I have two stacks one destined to be the application stack and the other for data.
In the application stack, upon navigating to the data stack I set a custopmproperty of the data stack to "go" or "stop". When navigating from the app stack to the data stack, I set it to "go".
Upon closing the data stack, it is set to stop.
This is my method to prevent opening the data stack without going through the application stack.
This is working fine as far as switching back and forth from go to stop.

However, I put a preopenstack handler in the stack script of the data stack and, regardless of the cp being "go" or "stop" it seems to ignore that state as if it were always "stop".

on preopenstack
if the good of this stack <> "go" then -- the cp is titled "good" and in this case it contains "go"
wait 10 secs -- this to test rather instead of "quit". That hurt the first time
pass preopenstack
end if
end preopenstack


Again, the cp "good" contains the right values when they are switched.
I see no errors thrown, but it doesn't matter how the stack is opened, I have to wait 10 seconds for this test.

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

Re: My preopenstack handler missing something

Post by dunbarx » Fri Dec 15, 2023 8:50 pm

Hi.

Do I assume there are two stacks because this is eventually going to be a standalone, and the "Application" stack is a "splash" stack that is only used to allow you to navigate to the data stack where changes can be made and saved? If so, common practice only uses that stack as the executable, with a handler in it to navigate to the "real" stack(s) and then, usually, to simply hide itself.

This will all be pointless if the application stack is part of your, er, application. But I recommend against that, since, mainly, you cannot save anything to it it at all.

Do I have any of this right? If so, we might talk about a simpler way to get started.

Craig
Last edited by dunbarx on Fri Dec 15, 2023 8:52 pm, edited 1 time in total.

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

Re: My preopenstack handler missing something

Post by dunbarx » Fri Dec 15, 2023 8:51 pm

Also, please put your handlers inside the code tags, "</>"like so:

Code: Select all

do this
do that
do something else
Craig

stam
Posts: 2692
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: My preopenstack handler missing something

Post by stam » Fri Dec 15, 2023 10:45 pm

oldummy wrote:
Fri Dec 15, 2023 7:47 pm
I have two stacks one destined to be the application stack and the other for data.
In the application stack, upon navigating to the data stack I set a custopmproperty of the data stack to "go" or "stop". When navigating from the app stack to the data stack, I set it to "go".
Upon closing the data stack, it is set to stop.
This is my method to prevent opening the data stack without going through the application stack.
This is working fine as far as switching back and forth from go to stop.

However, I put a preopenstack handler in the stack script of the data stack and, regardless of the cp being "go" or "stop" it seems to ignore that state as if it were always "stop".

Code: Select all

on preopenstack
   if the good of this stack <> "go" then -- the cp is titled "good" and in this case it contains "go"
      wait 10 secs -- this to test rather instead of "quit". That hurt the first time
      pass preopenstack
   end if
end preopenstack
Again, the cp "good" contains the right values when they are switched.
I see no errors thrown, but it doesn't matter how the stack is opened, I have to wait 10 seconds for this test.
Have you set a breakpoint to step through the code and see if the value of 'the good' is set and what it is?

Having said that, there is I think an issue with your if statement logic:
Regardless of the value, the stack will (or should!) just appear - if it's not 'go' it will simply pass the preOpenStack handler, which kicks it up the object hierarchy but unless you do something with it at stack or frontScript level, it will end up the same as end preOpenStack. And if it's 'go', well nothing will stop the stack from launching, so the end-result is the same.

Regarding the 10 sec delay (that's a really long delay!) - is that because you'd normally want quit the app, but you don't want todo this in the IDE (for obvious reasons)?

In that case you could instead use:

Code: Select all

if the environment is "development" then 
   close this stack -- or whatever other action you would do
else
   quit -- will only quit if not running from the IDE
end if
But if the intention is to simply close the stack if 'the good' is not 'go' then why not use

Code: Select all

on preopenstack
   if the good of this stack <> "go" then close this stack
end preopenstack
And finally: why have 2 stacks at all, and not use a subStack of the mainStack for the data? for all intents and purposes it's pretty much the same as a separate stack, but you'd always need to open the mainStack to access it. That sounds simpler to me...!

And yes, keep in mind what Craig said: if you create an app, any data in the app stack is 'frozen' - so typically a splash-screen stack is built as the app stack, which then opens the mainStack as per normal.

Stam

oldummy
Posts: 79
Joined: Mon Jun 13, 2016 3:21 pm

Re: My preopenstack handler missing something

Post by oldummy » Sat Dec 16, 2023 11:30 am

Firstly, I need to proclaim my ignorance in dealing with this scripting. Sometimes I may not state the issue I am having trouble with clearly.

Two stacks. I will call one "app" and one "data"I am aware that one cannot save anything to an application stack The app stack is not built yet.
I will build the app stack and add the data stack to the stackfiles upon building.
I want to use the application stack simply to set the customproperty in the data stack to it's "go " state and open the data stack, so that when the preopenstack handler in the data stack checks the state of the customproperty to see if it is "go", then it will continue to open that stack.
Upon closing the data stack, the same custompropery is set to stop, and will remain that way until the stack is opened through the application stack.
If, however, one tries to open the stack in the ide, the preopenstack handler will check and find "stop" in that customproperty, at which time it should quit.( or for test purposes,wait 10 secs.)
I put the 10 sec wait in there to test only. I'd already made the mistake of using quit and had to trash the stack and use a copy as it would never open.
My question: Why is the preopenstack handler proceeding as if that customproperty is set to stop, when the inspector shows it to be "go", and should open the stack.
Everything works well, except this.

on preopenstack
if the good of this stack <> "go" then --good is the custom property that contains "go'" or "stop" if it is "Go" then the stack should open with delay
wait 10 secs --regardless of the state of the customproperty this happens.
else
beep
pass preopenstack
end if
end preopenstack

oldummy
Posts: 79
Joined: Mon Jun 13, 2016 3:21 pm

Re: My preopenstack handler missing something

Post by oldummy » Sat Dec 16, 2023 11:37 am

Got it working!
I diddled with that preopnenstack handler and now it works. I feel I can safely change the wait ten sec to "quit" now.

on preopenstack
if the good of this stack <> "go" then
wait 10 secs -- now does not occur when cp is "go"
else
beep
pass preopenstack
end if
end preopenstack

Told you about that ignorance. Thanks for the offered help.

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

Re: My preopenstack handler missing something

Post by Klaus » Sat Dec 16, 2023 11:43 am

Please use the CODE Tags </> above after pasting your script(s):

Code: Select all

on preopenstack
   if the good of this stack <> "go" then
      wait 10 secs -- now does not occur when cp is "go"
   else
      beep
      pass preopenstack
   end if
end preopenstack

oldummy
Posts: 79
Joined: Mon Jun 13, 2016 3:21 pm

Re: My preopenstack handler missing something

Post by oldummy » Sat Dec 16, 2023 12:05 pm

It seems it works now, then does not work for a while. I seem to have gotten too optimistic.

oldummy
Posts: 79
Joined: Mon Jun 13, 2016 3:21 pm

Re: My preopenstack handler missing something

Post by oldummy » Sat Dec 16, 2023 1:06 pm

I simplified this handler in the data stack (testgenerator) as I should have at first to:

<on preopenstack
if the good of me <> "go" then beep
end preopenstack>

And regardless of if the good of the stack equals "go" or "stop" I get a beep
And yes, I do check the stack inspector to see what the cp has in it, and it always has the correct value in it whichever way I open it.


In the stack (Bookshelf)that sets the cp and navigates to the data stack I have the btn handler that sets the cp and opens the data stack.
Below:

<on mouseUp -- the cp always gets set correctly.
ask "PW?"
if it = the pass of stack"testgenerator.livecode" then --thats the data stack
set the itemDelimiter to "/"
get the effective fileName of this stack
set the defaultFolder to item 1 to -2 of it
if there is a stack "testgenerator.livecode" then
open stack "testgenerator.livecode"
set the good of stack "testgenerator" to "go"
close stack "Bookshelf" --to be the application stack. Not yet built
end if
end if
end mouseUp>

I only just figured out what "code tags " are. Sorry.

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

Re: My preopenstack handler missing something

Post by Klaus » Sat Dec 16, 2023 2:07 pm

Hi oldummy,

here some important hints in my comments:

Code: Select all

on mouseUp -- the cp always gets set correctly.
   ask "PW?"
   
   ## Always check if the user clicked "Cancel"
   if the result = "cancel" then
      exit mouseUp
   end if
   
   ## PASS is a reserved word in LC, like all resevered words this will get colorized in the script editor.
   ## To avoid possible problems use another name!
   ## I use C as a prefix, which also indicates that this is a custom property
   if it = the cPass of stack"testgenerator.livecode" then --thats the data stack
      set the itemDelimiter to "/"
      
      ## EFFECTIVE is only neccessary if the stack in question is a SUBSTACK of annother stack
      ## put the effective fileName of this stack
      
      put the fileName of this stack into tFileName
      
      ## item -1 = the last item
      put "testgenerator.livecode" into item -1 of tFileName
      
      ## No need to set the defaultfolder if we can have ABSOLUTE pathnames!
      ## set the defaultFolder to item 1 to -2 of it
      if there is a stack tFileName then
         open stack tFileName
         set the cGood of stack "testgenerator" to "go"
          close stack "Bookshelf" --to be the application stack. Not yet built
      end if
   end if
end mouseUp
Best

Klaus

oldummy
Posts: 79
Joined: Mon Jun 13, 2016 3:21 pm

Re: My preopenstack handler missing something

Post by oldummy » Sat Dec 16, 2023 2:44 pm

Ok I did find the cause. I put a simple "put the good of this stack" into a preopenstack handler, and sure enough the cp was still "stop" which would cause it all.The customproperty does not get changed until after the openstack handler runs. My ignorance again.
Klaus, thank you and I will give that a try after my head stops spinning from this.

stam
Posts: 2692
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: My preopenstack handler missing something

Post by stam » Sat Dec 16, 2023 3:49 pm

Also note that your previous 'if' statement won't stop the stack from opening, because "pass preOpenStack" doesn't do this.
If you mean to conditionally prevent the stack from opening you need something else like "close stack".
i.e.:

Code: Select all

on preOpenStack // this is in the 'data' stack
   if <condition false> then 
      close this stack
   end if
end preOpenStack

oldummy
Posts: 79
Joined: Mon Jun 13, 2016 3:21 pm

Re: My preopenstack handler missing something

Post by oldummy » Sun Dec 17, 2023 11:59 am

This is what I have at this time. It works consistently.
As I couldn't check the state of the cgood cp until after the openstack handler, I tried send in time, and it works. Crude and inelegant maybe.
I am going back through some of the advice given here and replacing this, as I would rather use best practices.


<on openStack
choose browse tool
put "" into fld "mylist"
send chekit to me in 1 sec
end openStack>



<on chekit --name change of cp good Thanks Klaus
if the cguard of this stack <> "go" then close this stack
end chekit>

-- apparently this lets openstack finish before
the cp state is confirmed correctly and acted upon.


Stam thank you, your suggestion works just fine and I will adopting that as it is simplest. Evidently I was enjoying running my head into the wall too much to try it first. But I did learn some things

<if the environment is "development" then
close this stack -- or whatever other action you would do
else
quit -- will only quit if not running from the IDE
end if>


And again, thank you all.

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

Re: My preopenstack handler missing something

Post by Klaus » Sun Dec 17, 2023 12:15 pm

oldummy wrote:
Sat Dec 16, 2023 1:06 pm
...
I only just figured out what "code tags " are. Sorry.
I'm afraid you didn't! 8)

Do not add the < and > manually, that are not the correct tags!
After pasting your script here, select it and click the CODE TAG icon in the little toolbar above the text entry field.
This way, the formatting (indenting etc.) will be preserved:
tags.png
tags.png (34.52 KiB) Viewed 92940 times

Code: Select all

...
if the environment is "development" then
   close this stack -- or whatever other action you would do
else
   quit -- will only quit if not running from the IDE
end if
...

stam
Posts: 2692
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: My preopenstack handler missing something

Post by stam » Sun Dec 17, 2023 2:15 pm

what the button Klaus points at does is add a [ code] and [/ code] tag around the selected text
(spaces added to prevent this from appearing as code ;) )

You can of course add these manually, the button just makes it simpler - select the text of code you want to hilite and click the button.

in other words when composing the message, it should look like this

Code: Select all

[code] --> a nested code tag for illustration
on myHandler
   Some code here
end myHander
[ /code] --> space added to ensure this tag appears as code

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”