Page 1 of 1

"Code Bank"

Posted: Fri Jan 21, 2011 3:07 pm
by jsburnett
Hi,
I was wondering what others do.
I seem to use the same code in multiple stacks (buttons, handlers, functions, etc).
Don't you?
I've 'heard/read' of some using some type of 'Code Bank' to keep all of these snipets of code for later use?
(Why reinvent the wheel each time you 'write' a new stack?)
Not sure how I would set up something like this or how it could work.
Would you use the stack as a 'substack' or use it to 'get' the snipets to transfer to your current project?
Would be interested in others experinces, thoughts, ideas, suggestions...

Thanks.

JSB

Re: "Code Bank"

Posted: Fri Jan 21, 2011 3:29 pm
by dunbarx
You are talking about a library of code. This can be easily done in several ways, A stack that is put in use becomes part of the message hierarchy, and will receive messages from all other stacks. See the dictionary under "start using". Also, read about the "insert script" command and the "back" keyword.

Lastly, read about plug-ins. there is a tutorial about these, and they can be loaded automatically on the start of each session.

Write back if you need more...

Craig Newman

Re: "Code Bank"

Posted: Fri Jan 21, 2011 8:21 pm
by jsburnett
hi,
Thanks for the reply.
Do you use one?
How did u organize it?
Thanks for pointing me in a useful direction.
JSB

Re: "Code Bank"

Posted: Fri Jan 21, 2011 9:21 pm
by dunbarx
JSB.

I use several of all types.

Open a working stack with multiple cards, or make a test stack with several cards.

Make a new stack, name it and save it. This will be your library stack. Type "start using this stack" into the message box and hit enter. Put a handler in its stack script that is likely to be caught by common processes. Let's try:

On preOpenCard
beep 3
put the target
end

Navigate around your working stack. Every time you change cards, you will hear three beeps, and the name or id of that card will appear in the msg box. Play around with this. There is no reason you cannot keep this stack forever as your library. Again, read about inserting scripts "into back" (the "insert script" command).

Now put a custom handler in the stack script of the library stack, like:

on catchMyMessages
beep 5
end catchMyMessages

or if you are bold:

on catchMyMessages
answer "The random number" && random(99) && "was sent from" && the target && "of" && the owner of the target && "of" && the name of this stack
end catchMyMessages

Go back to your working stack and place this in the script of a button:

on mouseUp
catchMyMessages
end mouseUp

Click on the button. Getting it? Note that if you trap "preopencard" in your working stack, the message will not be passed along unless you explicitly pass it. This is a common trap when enhancing the message hierarchy. You have to watch that sort of thing...

Craig Newman

Re: "Code Bank"

Posted: Sat Jan 22, 2011 9:15 am
by kray
Take a look at the excellent Scripter's Scrapbook by Hugh Senior at Flexible Learning for a great way to organize code snippets.