[9.9] How can I move a scrolling field to a particular line?

A scrolling field will scroll to display a line where you've just made a change, so to move a particular line into the field, you can use:

put empty before line whichLine of field whichField

However, this will only scroll the line into view, it won't necessarily position the line where you want it. Suppose your field can hold 9 lines before scrolling, and you've put twenty lines of text in it. If it starts out with line 1 at the top, saying

put empty before line 6 of field thisField

will have no effect, since line 6 is already onscreen. If you're anxious to actually scroll a particular line to the top, you might do something like this:

-- this takes a sprite rather than a field in order to
-- evaluate its height - doing this with the cast leads
-- to grief

on moveLineToTop whichLine, whichSprite
  -- determine the field number
  put the castNum of sprite whichSprite into whichField
  -- work out how many lines are visible
  put the textHeight of field whichField into txHt
  put the height of sprite whichSprite into Ht
  put Ht/txHt into lineOffset
  -- jump to the top of the field
  put empty before line 1 of field whichField
  -- and then jump down as many lines *after* the one we want as
  -- will fit within the scrolling field
  put empty before line (whichLine + lineOffset) of field whichField
end moveLineToTop

However, this does produce a nasty flicker while you jump to the top of the field, so it's best done with the relevant sprite somewhere offstage or invisible.