Articles Archive
Articles Search
Director Wiki

Object Oriented Scripting

November 13, 1997
by Alex Zavatone

If you are just getting into object oriented programming or are still struggling with the concept, I've created a handler to add to your object oriented scripts to help you out.

See, a long time gripe of mine has been that you can check all your global values, all your local values but you can't check all the properties in your objects. Now with a bit of trickery it is possible and that trickery is provided in the lingo at the end of the article. Just copy and paste it into each of the objects who's properties you want to check and it will spit back a list which lists each property and it's value.

How does it work?

Surprisingly, the property list commands work rather well to dive into an object and pull out it's properties. The only problems are getting a grip on what list commands to use. As you can see below, they can get a bit sticky. The getPropAt command allows Lingo to pull the property name from the object.

Then after that has been done, you can get the value for that property with the getProp command but you must nest the property name inside the getProp or it will not work. So to get this to work, simply add this handler to your bottom of your object oriented scripts

on ShowProps me
  set myProps = [:]

  repeat with myPropIndex = 1 to count(me)
    put getPropAt(me, myPropIndex)
    put getProp(me, getPropAt(me, myPropIndex))
    addProp myProps, getPropAt(me, myPropIndex),¬
          getProp(me,getPropAt(me, myPropIndex))
  end repeat
  return myProps

and then after you define your object, you can display the current value of it's properties by calling the handler with the object variable inside the parens like so:

put ShowProps(myObjectReference)

And you've got the names and values for your properties of your object. If you're using inheritance, this script will not fetch all the properties in all the object's ancestors. To do that you've got to play some more tricks and it gets kinda cumbersome coding it and understanding the output.

For that type of indepth monitoring, its best to have a window running that outputs all the object/ancestor properties. Till you need that type of control, I hope this script will help in your OO endeavours.

A Director user since 1987, Alex (Zav) Zavatone has worked on the engineering teams for both Director and Shockwave, 4, 5, 6 and 7. Recent investigations find him developing foundation classes for Director with asynchronous process management and other life threatening activities. In its early days, he had something to do with this Internet thing known as "DOUG". A noted ne'erdowell, slacker and laggard, Mr. Zavatone is nonetheless is trusted by children, small animals and the elderly. In his spare time, Mr. Zavatone rehabilitates lame desert trout.

Copyright 1997-2017, Director Online. Article content copyright by respective authors.