Tim Dietrich

Custom Software Developer

Home Services Portfolio Blog About Contact Newsletter

LiveCode: An Example of the Language

I wrote last week about my quest for another development environment - one that supports creating native apps for targets that include OS X, Windows, iOS, and possibly Android. I've evaluated Xojo, and I'm now putting LiveCode through its paces as well.

In that post, I had mentioned that LiveCode's language is based on the old HyperTalk language. It is "English-like," but at times that seems like a stretch. Sure, it's easy for people to read. However, it can be a bit difficult to write.

A number of you emailed and asked what the LiveCode language looks like. Here's an example:

on mouseUp
     
     // Change the shape of the cursor
     set the cursor to watch
     
     // Ask the user to select an image file.
     answer file "Please select a photo." with \
               type "All Images|jpg,jpeg,gif,png|JPEG,GIFf,PNGf" or \
               type "JPEG Images|jgp,jpeg|JPEG" or \
               type "GIF Images|gif|GIFf" or \
               type "PNG Images|png|PNGf"
     
     // If a file was selected...
     if it is not empty then
                       
          // Grab the path of the file.
          put it into filePath
          
          // Load the file into the "ImageUpload" image.
          put url ( "binfile:" & filePath ) into image "ImageUpload"
          
          // Get the file's name from the path.
          put filePath into pathParts
          split pathParts by "/"
          
          // This is how we get the number of elements of an array. Weird!
          put the number of lines of ( the keys of pathParts ) into pathPartsCount
          
          // Set the tooltip of the image to the file's name.
          // We use this later to pass along the Base64 encoded image and its file name.
          set the toolTip of Image "ImageUpload" to pathParts[ pathPartsCount ]
          
     end if
     
end mouseUp

As you can see, the code is very easy to read - and I think you would find it just as easy to read without the comments. But try to imagine writing it. While the language is English-like, it isn't particularly intuitive -- especially to someone that is new to it.

Also, take a look at this:

     put the number of lines of ( the keys of pathParts ) into pathPartsCount

That's a long-winded way of asking for the number of elements of an array. There might be (and I'm hoping that there is) a better way to do this. But I have searched the LiveCode documentation, and I haven't found anything to indicate that you can easily do this with a simple function.

In any case, I'm still very pleased with LiveCode. I've been experimenting with it, and have made a lot of progress. For example, I'm now able to get a LiveCode-based client to push both standard data (text, numbers, etc) as well as binary data (images in Base64-encoded format) to a hosted FileMaker database. While the learning the language has been frustrating at times, I'm having a lot of fun doing so.