Adobe Director: Redfining ‘Put’ for debugging purposes

When debugging projectors, there are times when you need a log file or a message window to help out with fixing issues. There are ways to open up a message window directly inside of a projector, but there are scenerios where that’s not useful: either too much is being dumped to the message message window, or the bug occurs on a third-party’s machine who isn’t the developer themself. In the past I’ve written a custom debugLog() function and then called it with messages that I wanted to keep track of, but this method isn’t compatible with the way most of us use the message window in Director: the “put” command, which means going back and changing the important Put commands to Debuglog().

Recently I did a little experiment to see if I could simply redefine the Lingo Put command to trigger my own function. In a movie script, I did this:

on put(imsg)
trace(string(imsg)) & "!"
end
When I ran my project, all the same data was showing up in the message window, but with exclamation points on the end of it. It does indeed work. This means it should be pretty easy to write a logger for Put, like so:
global logfile

on put(imsg)
logfile = logfile & string(msg) & return
trace(string(imsg))
end

Or, we can change Put to add timestamp to every message:

on put(imsg)
imsg = the long date && the long time && imsg
trace(imsg)
end

there’s lots of useful things we can do with this. But what’s great about this is that it allows the conversion of an existing command into a customized function, instead of having to write a whole new funtion and change our code (and coding habits) to use the new function.

Notes


There’s a couple of things I want to mention here.
I still use the old-school method of using “put” to write messages to the message window, instead of the newfangled trace() function that’s all the rage now. I assume that if you use Trace instead, you could redefine Trace.

But notice I use Trace() inside of the custom Put function. This is because (A) I still want my messages to go to the message window and (B) I didn’t want an endless loop triggered. Calling Put inside of Put wouldn’t get us anywhere (I’m assuming; I didn’t try it). Luckily for us, Director does have two different commands for outputting to the message window. If you’re redefining Put then use Trace() inside of it. If you’re redefining Trace() then use put. It’s simple.

Also, I never ever use Putfor anything other than putting to the message window. You won’t find Lingo that looks like this is my code:
Put the contents of NameString into member "Textfield"
I have no idea whether the new put function will break uses of Put for assignment tasks. I actually don’t even know if the above sample is syntaxically correct. I’ve been using Director since dot synax was released, and don’t really know how to use the old format.

I hit on this idea after realizing I could redefine Lingo commands when I got stumped on one of the easiest-to-make mistakes in Director: I had Parent Script Lingo in a script that was actually set to be a Movie script. If you’ve ever made this mistake you know that it breaks Lingo’s New command, becuase as a movie script it redefine’s lingo’s New command. I figured if it worked for New, it could work for Put. And I was correct.


One Response to “Adobe Director: Redfining ‘Put’ for debugging purposes”

  1. Raman Says:

    Definitely an interesting perspective on a put statement.

Leave a Reply

For security, enter the word TURING below:
Comments RSS feed