Version:

Lua Editor

Lua Editor


This feature is in preview release and is subject to change.

Lumberyard Lua Editor (Lua IDE) offers an intuitive integrated development environment (IDE) that makes it easy to author, debug, and edit Lua scripts when you create or extend your game. Lua Editor is a standalone application, but can be opened directly from Lumberyard Editor using the Tools menu.

Tutorial: Using Lua Editor for Debugging with Lumberyard Editor

This tutorial shows you how to use Lumberyard Editor to create a sample level in the SamplesProject project with a component entity that contains a Lua script component. You will learn how to open the script in Lua Editor and perform some sample debugging steps on the script.

Debugging Lua scripts using Lua Editor

  1. Set the SamplesProject as the default project using Project Configurator.

  2. In Lumberyard Editor, create a new level by performing one of the following steps:

    • In the Welcome to Lumberyard Editor window, click New level
    • Click File, New
    • Press Ctrl+N
  3. In the New Level dialog box, give the level a name, and then click OK.

  4. In Asset Browser, expand SamplesProject, Objects, and SamplesAssets.

  5. Drag mover_display_smooth.cgf to the perspective viewport.

  6. In Entity Inspector, click Add Component, and then choose Scripting, Lua Script.

  7. In the Entity Inspector window, locate the Lua Script component, and then click the Pick Lua Script button next to the empty Script field.
    [Open the Pick Lua Script window from the Lua Script component]

  8. In the Pick Lua Script window, expand SamplesProject, Scripts, and Components.

  9. Click ConstantRotation.lua, and then click OK.

  10. In the Lua Script component, click the Open in Lua Editor button to launch Lua Editor.
    [Launch Lua Editor from Lua Script component in Lumberyard Editor]

    Because the debugging functionality is enabled through network sockets, you must connect Lua Editor to the target that is running the script before you can debug. In this tutorial, you connect to Lumberyard Editor. Note
    Connection is facilitated by GridHub, which is Lumberyard’s central connection hub for debugging. GridHub starts automatically when Lua Editor is started and must be running in the background for Lua Editor to find targets it can connect to.

  11. In the Lua Editor toolbar, click Target: None, and then click Editor(ID) to connect to Lumberyard Editor.
    [Target selector] Note
    You may need to expand the Lua Editor window to see the buttons on the Lua Editor toolbar for the next few steps.

  12. In the Lua Editor toolbar, leave Context setting at Default for the debugging context. The default setting is good for debugging component entity scripts such as the one in this tutorial. The Cry context option is for debugging legacy scripts such as those associated with Cry entities or the Game SDK.
    [Context selector]

  13. The Debugging icon turns green to show that Lua Editor and Lumberyard Editor are connected:
    [Lua Editor connected to Lumberyard Editor]

    Click Classes in the Class Reference to show the available Lua libraries. You can do the same for EBuses and Globals.
    [Classes Reference]
    [Classes] Note
    The class reference feature is active only for the default context and component entity scripts. This feature is not active in the Cry context, which exists only for backward compatibility.

    After you connect, you can pause the execution of a given script by setting breakpoints.

  14. In the Lua Editor toolbar, click the Breakpoints icon [Image NOT FOUND] to show the Breakpoints window.

  15. In Lua Editor, click one or more line numbers in the constantrotation.lua script to set one or more breakpoints. As you add breakpoints, the line number and script path for each are added to the Breakpoints window.

  16. In Lumberyard Editor, press Ctrl+G to run the game, or click the Simulate icon at the bottom of the viewport to enable game simulation and run scripts. Lua Editor opens with a yellow marker stopped on the first breakpoint that it encounters.
    [Debugger stopped on breakpoint]

    When execution is halted at a breakpoint, more information becomes available in the Lua Locals, Stack, and Watched Variables panes.

  17. Click the Stack icon [Image NOT FOUND] to show the Stack window.

  18. Click the Lua Locals icon [Image NOT FOUND] to show local Lua variables.

  19. Click Watched Variables icon [Image NOT FOUND] to open the Watched Variables window, where you can specify variables to watch.

  20. Press F11 a few times to step through the code. Note how the contents of the Stack, Lua Locals, and Watched Variables windows change. Tip
    For greater convenience, you can float or dock these windows.

  21. To detach from debugging, click Debugging.
    [Click to detach from debugging]

  22. In Lumberyard Editor, Press Esc to stop the game.

Options Available While Debugging

The following table summarizes common options available while debugging.


IconActionKeyboard ShortcutDescription
[Image NOT FOUND]Run in EditorAlt+F5Run in Lumberyard Editor.
[Image NOT FOUND]Run on TargetCtrl+F5Send script to the connected target and run it.
[Image NOT FOUND]Run/ContinueF5Run or continue running the current script.
[Image NOT FOUND]Step IntoF11Step into the function called on the current line.
[Image NOT FOUND]Step OutShift+F11Step out of the called function.
[Image NOT FOUND]Step OverF10Step over the function called on the current line.
[Image NOT FOUND]Toggle BreakpointF9Enable or disable a breakpoint on the current line.

Maintaining Separate Search Results

In addition to the usual search capabilities, the Find feature can display the results of four different searches separately.

To maintain separate search results

  1. Click the Find icon [Image NOT FOUND] or press Ctrl+F to perform searches in the currently open file, or in all open files.
    [Lua Editor Find dialog]

  2. Before starting a search, choose Find 1, Find 2, Find 3, or Find 4 to choose the window in which you want to see the results. You can maintain the results of four searches separately in the tabbed windows. The search results in the other windows remain unchanged.
    [Find Results]

  3. To go directly to the line in the code which a search result was found, double-click the line in the search results. Note
    In Lua Editor Preview, the line number shown in the Find Results window and the line number in the script pane differ by one. Tip
    For convenience, you can also dock or float the Find Results window.

Editing

Lua Editor can open multiple scripts at the same time. Each script has its own tab in the editor. The editor provides a standard set of capabilities for text editing but also includes useful features for editing source code.

The following table summarizes the options available while editing and debugging.


ActionKeyboard Shortcut
Comment selected blockCtrl+K
CopyCtrl+C
CutCtrl+X
FindCtrl+F
Find in open filesCtrl+Shift+F
Find nextF3
Fold source functionsAlt+0
Go to lineCtrl+G
PasteCtrl+V
Quick find localCtrl+F3
Quick find local reverseCtrl+Shift+F3
RedoCtrl+Y
ReplaceCtrl+R
Replace in open filesCtrl+Shift+R
Select allCtrl+A
Select to brace¹Ctrl+Shift+]
Transpose lines downCtrl+Shift+Down Arrow
Transpose lines upCtrl+Shift+Up Arrow
Uncomment selected blockCtrl+Shift+K
UndoCtrl+Z
Unfold source functionsAlt+Shift+0

¹ Select to brace selects a block bounded by braces. Before using this option, the cursor must be immediately next to the beginning or ending brace of the block.

Perforce Integration

Lua Editor includes Perforce integration features. When you open a file from your Perforce environment, Lua Editor displays the file’s status in the top right of the text editing window.

[Not Checked Out]

[Checked Out By You]

The Source Control menu offers Check Out/Check In functionality.

[Source Control Menu]