Page 1 of 1
on closeStack [Solved]
Posted: Wed Sep 02, 2015 10:04 am
by antrax13
Hi all,
its me again with funny issues
I have the main stack where I put the connection/disconnection on openStack/closeStack.
Code: Select all
on openStack
connectDB
end openStack
then I want to close connection when the stack is closed so I have
Code: Select all
on closeStack
closeDatabaseConnection
end closeStack
Now the issue is I have couple of cards and some substacks but as soon as I close
substackit will disconnect me from database because it will run closeStack that is on mainstack script.
So is there any function like on closeMainStack or to have:
if "only the particular name of the stack" is closed then closeconnection else do not close connection end if
The code that I need, must be on main stack script
In other words how can I close connection when the main stack is closed not substack
Re: on closeStack
Posted: Wed Sep 02, 2015 10:33 am
by jmburnod
Hi antrax13,
if "only the particular name of the stack" is closed then closeconnection else do not close connection end if
Yes you're right, you can check the name of stack like a condition
You can also use pass closestack if you want do something on closestack for the current stack and pass closestack
Best regards
Jean-Marc
Re: on closeStack
Posted: Wed Sep 02, 2015 10:44 am
by antrax13
jmburnod wrote:Hi antrax13,
if "only the particular name of the stack" is closed then closeconnection else do not close connection end if
Yes you're right, you can check the name of stack like a condition
You can also use pass closestack if you want do something on closestack for the current stack and pass closestack
Best regards
Jean-Marc
could you help me with syntax because I have
Code: Select all
on closeStack
if stack "TestingStack" is closed then
answer "mainstack has been closed"
--closeDatabaseConnection
else
answer "substack has been closed"
end if
end closeStack
is giving me error stack "TestingStack": execution error at line 8 (Chunk: source is not a container), char 1 ===> Line 8 is if stack "TestingStack".....
Re: on closeStack
Posted: Wed Sep 02, 2015 10:53 am
by antrax13
OK got it
Code: Select all
on closeStack
put the short name of this stack into tStackName
if tStackName is "TestingStack" then
answer "mainstack has been closed"
closeDatabase
else
answer "substack has been closed"
end if
end closeStack
Re: on closeStack [Solved]
Posted: Wed Sep 02, 2015 11:06 am
by antrax13
Just checking with me colleague and he also suggested another solution to have empty
Code: Select all
on openStack
end openStack
on closeStack
end closeStack
on substacks
Re: on closeStack [Solved]
Posted: Wed Sep 02, 2015 11:18 am
by bn
Hi Antrax
the problem here is that when you close a substack the substack gets a message "closestack". Since the substack apparently does not handle this message the message travels along and finds in the message path the main stack, which has a closeStack handler.
If your substack includes a
handler in the stack script the message would stop there and never reach the main stack.
Of course Jean-Marc's approach is perfectly alright and might in some circumstances be the only way. E.g. the mainstack has to do something when the substack closes.
This is just to remind you of the message path which can at times surprise
Kind regards
Bernd