where I put my scripts
Steve Messimer
steve at messimercomputing.com
Fri May 3 08:44:00 EDT 2002
Hey Dar,
Question: Where do I put my scripts.
Short Answer: pretty much where ever it makes sense. ;-)
Seriously, script placement for me is pretty much a moving target. When I am
beginning a project I generally place scripts in the target object. There
are some exceptions to this rule. Handlers that are fairly ubiqitous like
navigation handlers can be placed somewhere up the msg path. If I have the
time I will try to do this with other types of handlers as well. It saves
me time and simplifies debugging. There is a trade off however. In some
cases it might be faster to place the handler in the target object. It just
depends.
In addition to the objects that you mentioned I also store scripts in custom
properties. I have found that it is very useful to have the ability to alter
an object's script on the fly. If an object is in a certain state it will
use script "A" when it is in another state it will use script "B". This is
a very powerful technique and one of the really cool things about Rev. I
used to do this with flds in HyperCard. Custom properties are superior tho
because you can set them or get them with ease and the user doesn't have a
way of accessing them.
Steve's script placement rules ...
1. The less code the better.
2. If you can write a series of commands and functions that live at the
stack level and can be called from any object in the stack, do so, because
it will save you time in the end.
ex.
Button does all the work. Every next nav btn needs this script
on mouseup
statement...
statement...
go next
end mouseUp
alternantive: btn sends a msg to the "g" handler at the stack level
on mouseUp
send g to stack yourStack
end mouseUp
Script at stack level traps g msg sent from any btn.
on g
statement...
statement...
go next
end g
This is the way I learned to do it. I would also be interested to hear how
others approach this.
Steve
More information about the use-livecode
mailing list