How do I use a built in function in my solution?
What is a Function
A function is a block of LiveCode Script that performs a single piece of functionality.
The Function Workspace
The Functions pane of the LiveCode for FM Workspace shows a list of functions, and their names, descriptions, code and parameters.
From the Workspace you can view, clone, add and delete functions.
Function components allow you to write a custom function in LiveCode Script and execute it within your solution via the LC plugin function.
Functions are extremely flexible and can return anything from the value of a calculation to an image.
How to use a Built In Function in your Solution
In this lesson we will see how to use one of the built in functions within a FileMaker solution.
The example we will be using the LCProgressBar. This function takes 2 parameters, the value to be shown on the progress bar (as a percentage) and the width of the progress bar, and returns an image of a progress bar which can be shown in a container.
The LC Plugin Function
Function components can be used via the LC plugin function.
LC ( <function-name>, <parameter list>)
Functions require no action, and calling them executes the script defined for them in the workspace.
Set Variable [ $doesitexist ; Value: LC ( "lcFileExists" ; "~/Desktop/MyFile.txt" ) ]
Will set the $doesitexist variable to true if there is a file "MyFile.txt" on the user's desktop.
The Sample Solution
The attached solution is a simple task list, each task has 2 fields
- Task name
- Status, one of
- Not started
- In progress
- Awaiting signoff
What we want to do is add a progress bar that shows the level of progress on the task, as defined by the 'status' field.
I have added a container named 'progress' to the layout.
Setting the Progress Bar
When a record is opened we want to show a progress bar that represents the status.
- Not Started = 25%
- In Progress = 50%
- Awaiting Signoff = 75%
- Completed = 100%
Add a script to the FileMaker Script workspace. The script checks the value of the 'status' field and sets the value of the 'container' field to the value returned but the LCProgressBar function.
If [ taskList::Status = "Not Started"] Set Field [ taskList::progress ; LC("LCProgressBar";25;200) ] Else If [ taskList::Status = "In Progress"] Set Field [ taskList::progress ; LC("LCProgressBar";50;200) ] Else If [ taskList::Status = "Awaiting Signoff"] Set Field [ taskList::progress ; LC("LCProgressBar";75;200) ] Else If [ taskList::Status = "Completed"] Set Field [ taskList::progress ; LC("LCProgressBar";100;200) ] End If
Calling the Script when a Record is Opened
The FileMaker script must be called when a record is opened so the progress bar is updated with the correct value.
Open the Layout Manager, select the layout and go to the Script Triggers. We want the progress bar to be updated when a record is opened so select the 'OnRecordOpen' event and set the script to the "progress" script.
Test the Progress Bar
Switch to Browse mode and try it out.