Message Paths

The Message Path - 

            LiveCode follows a specific path when it looks for message handlers. It looks in the following order:

                    first - the object
                    next - the group of objects (if any)
                    next - the card
                    next - the stack
                    next - LiveCode engine

                (also other places too but we do not need to list them all here)

            ... more to come


How Can We Use This to Our Advantage?
Good question. When possible, move scripts higher on the message path. Any time that you find yourself writing the same code more than once, think about moving it higher up the message path and only write it once.

This is similar to the concept of inheritance In Java, and other languages.

Let's say you were making something with many buttons - a calculator, a keyboard, a memory game or anything else with many buttons. It would be tedious putting the same code on every button or object. Then if you would make a change, you would have to edit each one at a time.

Wouldn't it be easier just putting 1 copy of the code on the card script and have it see which button was pressed? 

Yes, for instance a calculator. You would have 10 buttons for the numbers (0 to 9) and normally would put code on each one. 

    On button "B1" - the button with the "1" on it

       on mouseUp
                put "1" into field "number"
       end mouseUp

    On button "B2" - the button with the "2" on it

       on mouseUp
                put "2" into field "number"
       end mouseUp
 

(note: we used "B1" for the name and "1" for the label. It is not a good idea to name any object with just a number. LiveCode does not know id you mean the ID or the name of the object. So instead we include a "B" before each number - as the name)

Instead, you can just do one script on the card 

    on the CARD Script

        on mouseUp
                
put char 2 of the short name of the target into the field "number"
        end mouseUp

A little more complicated (not really if you understand it) but a lot less work. You are done. You do not have to do any more scripts

(If you do not understand about the "target" , read the page about objects

Comments