A script with two points as argument

We will write a simple script to calculate the distance between two points. Note that this feature is built in DrGeoII.

To handle the arguments in our script we use the Smalltalk keyword-message. The argument of our script are two points called pointA and pointB. Before going further, I need to explain the nature of the arguments sent to script.

Nature of the argument

From the user point of view, the argument sent to a script is related to the item selected in the figure by the user. From an internal point of view, this argument is the model object of this visual item. To be accurate we have three layers to represent a geometric item: its models, its costume and its morph, the one the user see in the drawing area. The model of the items are all subclasses to the DrGMathItem.

Therefore the point arguments of our script are instances of DrGMathItem subclasses, exactly DrGPointItem.

Back to our script

Our script comes with two arguments, we can call it @distance:to:@, it is a two-keyword message. From the DrGeoII pop up menu, we open the script browser numerics>edit script and input our script content:

Un script avec deux arguments

Next, we create two points in the drawing area and we open the script wizard dialog from the menu numerics>use script.

Inserting a two arguments scipt in a drawing area

From the wizard dialog, select our distance:to: script, then select the two points, the selected points are flashing, then click somewhere in the drawing area to plug our script.

With the mouse over a script plugged in the figure, we have interesting feedback about its name and its arguments name:

Script feedback

Conclusion

In this article we have explained:

  • the nature of the arguments received by the script,
  • how to write keyword message
  • the use of script in a drawing area

In a next article, we will expose a more complex use of Smalltalk script.