Page 1 of 1

Scripting in the Stack vs the Card

Posted: Sun Oct 11, 2015 3:07 am
by CoreySchroeder
Hey there,

I've done a few small applications - all of which have used only one card - so I had all of my code in one place.
I didn't even use the script editor for the individual objects - everything was in the card script.

So my question is this -
What are the pros and cons to having all of your code in one place?
Instead of having your code split amongst the various cards, why couldn't I have it all in the stack?

I kind of like having everything right in front of me, versus needing to flip back and forth amongst cards to find and edit what I need.

I'm just thinking long term here - once I start developing larger apps that have several cards, lots of variables, etc.
I don't want to start off by creating bad habits.

Re: Scripting in the Stack vs the Card

Posted: Sun Oct 11, 2015 4:15 am
by dunbarx
Hi.

Thiis is a question that is both a matter of style and a matter of functionality.

For the funtionality part, Imagine you had a multi-card stack, where a backGround field contained the number of the card the user was on. If you had a fixed number of cards, you could just put the card number in the field, right? But what if cards were added or deleted? Then the numbers would be incorrect.

So the way to do that is to have a field, and load the card number using the "openCard" message:

Code: Select all

on openCard
put the number of this card into field "cardNumber"
end openCard
Right? Now we are using a dynamic property instead of a fixed value, iBut where does this handler HAVE to be placed? Why, in the stack script (or higher, but that is another story).

As for that style thing, keeping all your handlers in one place, if that is your comfort level, well, OK. I like to have button scripts in my buttons. It has the advantage of not needing to manage the targets of every mouseUp handler on the planet, knowing where my handlers are, and similar issues. But functionally, it could be done your way. I certainly always have function and command calls in the card or stack scripts, unless they are directly and locally married to the calling handler,

Craig Newman

Re: Scripting in the Stack vs the Card

Posted: Sun Oct 11, 2015 4:39 pm
by jacque
It's largely a matter of style, but the general rule is to put the handler at the level where all objects that use it can find it but no farther. If a button uses a unique script, then put it in the button. If all buttons on the card use it, put it in the card. Handlers that work with all objects in a group go into the group, handlers used by many cards go into the stack, and so forth.