Page 1 of 1
Setting up a substack Library
Posted: Tue Jun 04, 2013 9:16 pm
by daryl
Hi Folks,
I would like to start a library of code that can be called from different cards. After reading up on the subject it seems like the way to do it is as follows:
1. Create a new substack, name it.
2. add: start using stack "stackname" to the preOpenStack message of the first card of the mainstack.
3. start using the library functions.
Unfortunately I keep getting the error:
"... (Handler: can't find handler) near openNetworkConnection"
I have a function called openNetworkConnection in my library, which I am trying to call with two parameters as follows:
openNetworkConnection(useSSL, theDestination)
from one of the mainstack's cards. Any help, pointers to documentation, etc. would be greatly appreciated. I have read the documentation available at:
http://livecode.byu.edu/messages/libraries.php
Thanks,
Daryl
Re: Setting up a substack Library
Posted: Tue Jun 04, 2013 9:35 pm
by Klaus
Hi daryl,
sounds you made everything right!
Make sure that the stack is really loaded as a library, enter this in the message box: put the stacksinuse
The name of the substack should appear in that list.
Could you please post the code you are using to:
1. use the lib
2. the function in the lib itself
3. how you use the function in one of the mainstack's cards
Best
Klaus
Re: Setting up a substack Library
Posted: Tue Jun 04, 2013 9:36 pm
by dave_probertGA6e24
Just a quick question - for clarification.
Is the openNetworkConnection a 'function', 'command' or 'on' type of thing?
eg.
Code: Select all
function openNetworkConnection p1,p2
...
return xx
end openNetworkConnection
or
Code: Select all
on openNetworkConnection p1,p2
...
end openNetworkConnection
If it's the former are you using it like this:
put openNetworkConnection("xx","yyy") into qqq
or simply this:
openNetworkConnection("xx","yyy")
Because the latter route is likely to fail (functions always return values and need to have them put somewhere) with a message similar to your one.
Regarding the Library aspect in general, do you know wether it is loading OK?, can you call other handlers from it? Is it only this one handler/function that is failing?
To test the library simply make a small handler such as:
Code: Select all
on testLibCall p1
put "TESTING: "&p1&cr after msg
end testLibCall
and call it from a button somewhere on your parent stack. Look at the messageBox to see the output.
If all the above makes sense already then please ignore this post
Cheers,
Dave
Re: Setting up a substack Library
Posted: Tue Jun 04, 2013 9:44 pm
by daryl
Hi Dave,
Thanks so much for your quick reply, I appreciate it. Your suggestions did the trick, my problem was in the way I was calling the function; I was returning a value but was not putting into anything. As soon as I changed it to: put openNetworkConnection into networkStatus it started working as expected.
On a connected note, do you know if it is alright to put both functions and commands and handlers into the same library?
Thanks again, and best regards,
Daryl
Re: Setting up a substack Library
Posted: Tue Jun 04, 2013 11:27 pm
by dave_probertGA6e24
As long as you clearly document the functions/handlers then I would say yes.
But it's really down to personal preference in the long run.
I would also recommend for you to develop a naming convention regarding them - possibly prefixing (or postfixing) the names with "func_" (or "_func") when they are functions. This would make them obvious when re-reading your code at a later date (I know it's helped me immensely in the past to make sure that when I come back to old code it's as easy to read as possible - without needing to dredge up the old memories of when I created it). Even times as long as 2.5 minutes often make my medium-old brain confused
But all the above are only guides - not carved in stone, so just as long as you are happy with whatever you create - that's the most important thing. Unless you release it Commercially or Open - then be rigorous in your naming/parameters/documentation
Sorry, I could get TL;DR;
Cheers,
Dave
Re: Setting up a substack Library
Posted: Wed Jun 05, 2013 12:37 am
by daryl
Thanks,
Not TL;DR; by any stretch. I agree whole heartedly about having good documentation and naming conventions. Thanks for your thoughts on this.
Regards,
Daryl