Skip to main content
warning

This guide has been written using AI. This warning will be removed once its contents have been checked over by a human.

Script Writing in LiveCode Create

This guide explains how to get started with script writing in LiveCode Create, where to write your scripts, and how to integrate scripting with visual workflows.


What is LiveCode Script?

LiveCode Script is a high-level programming language known for its English-like syntax. It is simple to read and write, making it ideal for programming beginners, yet it provides powerful functionality for app development.

Key Benefits of LiveCode Script:

  • Easy to Learn: No complex symbols—commands and expressions are written in plain English.
  • Powerful: Automate processes, manage data, and create custom behaviors.
  • Flexible: Combine scripting with Actions to enhance workflows.

Example: A simple script to show a message when a button is clicked:

Button Script
on mouseUp  
answer "Hello, LiveCode Create!"
end mouseUp

Accessing the Script Editor

The Script Editor is where you write and edit LiveCode Script. To access it:

  1. Using the Script Editor icon:

    • Select the object you with to edit in the Canvas Area
    • Click the Script Editor icon along the bottom of the app
      Script editor icon
  2. By Right-Clicking a Control:

    • Right-click any widget in the Canvas Area.
    • Select Edit Script from the context menu.
  3. From the Project Browser:

    • Right-click a widget, layout, or object's item in the Project Browser.
    • Select Edit Script.
  4. Using the Message Box:

    • Open the Message Box and type:
Open Script Editor
edit the script of [control]

Replace [control] with the control’s reference, like button "SubmitButton".


Features of the Script Editor

The Script Editor provides tools to make script writing simple and efficient:

1. Code Writing Area

Write and edit your LiveCode Script here. It includes:

  • Syntax Highlighting: Automatically color-codes keywords, functions, and variables for readability.
  • Line Numbers: Navigate and reference lines of code easily.
  • Auto-Completion: Speeds up writing by suggesting common commands, functions, and variable names.
  • Auto-Indentation: Keeps your code neat and structured.

2. Error Highlighting

The Script Editor highlights syntax errors in real-time to help you identify and fix issues quickly.

3. Run and Test

Save and test your scripts directly in the IDE by switching to Run Mode. This allows you to see the effects of your script immediately.


Writing Your First Script

Here’s how to write a simple script in LiveCode Create:

Step 1: Select the Object

  1. Add a Button Widget to your layout.
  2. Right-click the button and select Edit Script.

Step 2: Write the Script

In the Script Editor, enter the following code:

Simple Button Script
on mouseUp  
answer "Button Clicked!"
end mouseUp
  • on mouseUp: The event that triggers when the button is clicked.
  • answer: Displays a message to the user.

Step 3: Save and Test

  1. Click Save to save your script.
  2. Switch to Run Mode.
  3. Click the button to see the script in action.

Mixing Script with Actions

LiveCode Create allows you to use both visual Actions and custom script seamlessly:

Using Raw LiveCode Script Blocks

In the Workflow Editor, you can add Raw LiveCode Script Blocks to insert custom code directly into your workflow:

  1. Open the Workflow Editor.
  2. Drag a Raw LiveCode Script Block from the Action Library.
  3. Write your script inside the block:
Raw Script Block
put "Welcome to LiveCode Create!" into field "WelcomeMessage"

Viewing Script for Actions

Every Action Block in the Workflow Editor generates LiveCode Script automatically.

  1. Expand Blocks: Click the Expand icon to see the generated script.
  2. Toggle Script View: Switch to Script Mode to view all the script for the workflow.

Unlocking Actions:

  • In Script View, click the Padlock Icon to unlock an Action Block.
  • The block becomes a Raw LiveCode Script Block, allowing you to modify the script.

Example: Customizing a Workflow with Script

Imagine you want to navigate to a layout and show a dynamic message:

  1. In the Workflow Editor:

    • Drag the Navigate to Layout Action.
    • Drag a Raw LiveCode Script Block after it.
  2. Add Custom Script:

Custom Workflow Script
go to layout "Dashboard"  
answer "Welcome to the Dashboard!"
  1. Save and test the workflow to see the result.
    Script editor workflow

Advanced Script Features

Variables and Data Handling

You can use variables to store and manipulate data in LiveCode Script:

Using Variables
local tName  
put "John Doe" into tName
answer "Hello, " & tName

Loops and Conditionals

Add logic to your scripts using if/else statements and loops:

Conditionals and Loops
repeat with i = 1 to 5  
put "Item " & i into line i of field "ListField"
end repeat

Best Practices for Script Writing

  1. Start Small: Begin with simple scripts and test them frequently.
  2. Comment Your Code: Use comments to explain what your script does.
Adding Comments
# This script shows a welcome message  
on openCard
answer "Welcome to my app!"
end openCard
  1. Use Descriptive Names: Name variables and objects clearly for readability.
  2. Combine Actions and Script: Use Actions for common tasks and script for advanced behaviors.
  3. Test Often: Test scripts in Run Mode to ensure they work as expected.

For further learning:

Thank you for your feedback!

Was this page helpful?