The DO Command

Ken Ray kray at sonsothunder.com
Sat Apr 12 15:48:15 EDT 2008


On 4/12/08 1:57 PM, "Joseph Martinez" <developer at positivepractices.com>
wrote:

> To save considerable development time, I make extensive use of the "do"
> command for creating of an app intended eventually for cross-platform
> distribution.  Is this asking for trouble?
> 
> I only use "do" with one-line type handlers, such as
> 
> Put "put doublespace(fld" && x & ") into fld" && x into tCmd
> Do tCmd

Well actually there shouldn't be a need for "do" in this instance; is there
some reason you can't write:

  put doublespace(fld x) into fld x

?

In most cases you'll find that "do" is rarely needed; Rev's code is
inherently cross-platform without any need for "do". I think you may be
confusing the "alternateLanguageName" used with "do" with the deployment on
different platforms, so let me clear this up for you if that's the case:

The "alternateLanguageName" is used by the "do" function to determine how to
*interpret* the text that's being "done". So you can "do" something as
"AppleScript" (if the text that is being "done" is in AppleScript), and in
Rev 2.9 you can "do" something as "VBScript", and if you have the proper
plugin, you can even "do" something as "JavaScript".

If you don't specify an 'alternateLanguageName', Rev will assume that the
text to be "done" is in proper Transcript (Revolution's native code).

Examples (I usually put the script to be done into a variable before "doing"
it):

  do "put the text of field 1 into field 2"  -- native Transcript (although
you wouldn't use it this way (see below))

  put "display dialog" && quote & "Hello" & quote into tScript
  do tScript as "AppleScript"
  -- if you tried to run the above without the "as AppleScript" you'd get an
error)

  put "Set App=Wscript.CreateObject(" & quote & "Wscript.Shell" & \
    quote & ")" & CR & "App.Run" && quote & \
    "C:\Windows\Explorer.exe /root,C:\" & quote & ", 1, False" into tScript
  do tScript as "VBScript"

As far as different computer platforms are concerned, 99% of Revolution's
code is naturally cross-platform and doesn't have to be adjusted. Some
exceptions that are platform specific are: AppleScript (Mac only) and
Registry manipulation (Windows only). There are others, but you get the
drift.

When writing cross platform apps, you may need to occasionally do an
"if-then" or "switch-case" if you're trying to do something that works
differently on different platforms. So for example, if you want to store
preferences; on Windows you may want to use the Registry, but on Mac you
would want to store files in the proper Preferences folder.

As to MacOS (classic) support, you can tell what's supported in the
different platforms by clicking on the Documentation button in the toolbar
and then clicking "Dictionary" in the documentation window's toolbar.
There's a column there that is "Platforms", and anything that doesn't work
on OS 9 will not have the blue "face" OS 9 icon. However 90+% of Rev code
works on OS 9 as well.

Hope this helps,

Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/





More information about the use-livecode mailing list