The following Lua script will not change anything in X-Plane. Its purpose is to demonstrate the input and output functionality that you can use when developing and debugging Lua scripts.

  1. Start GIT and a flight simulator so that the Virtual Cockpit is present (any aircraft is applicable).
  2. Open the Lua Console from the Status tab in GIT.
  3. Click the Create/Edit button and enter the filename my_first_script
  4. A text editor should now have started. Copy and paste the following into the text editor and save it:

    io.write("Enter your name: ")
    name = io.read()
    io.write("Enter your age: ")
    age = io.read()
    print("Hello, " .. name)
    print("You are " .. age .. " years old!")
    print("In ten years, you will be " .. age + 10 .. " years old!")


  5. Now make sure the my_first_script.lua is selected in the file list area and click the Run button. If error messages appear then its likely that your text editor understands HTML and has accepted the HTML code used to build this web page as well as the text above. To fix, simply copy and paste the above Lua code into Notepad (which will strip away any HTML code) and then copy and paste the Lua code from Notepad over the top of your previous pasted Lua Code from step 4.
  6. You should be prompted for your name in the output area. Click into the input area so the cursor is flashing in it and then enter your name.
  7. You should then be prompted for your age. Enter your age.
  8. You will then see several messages about you.

io.write()

This function displays text or variable contents into the Output area of the console. It is similar to print but does not move the output area to the next line, hence why the input, when entered appears on the same line as the io.write message prompt.

io.read()

This function waits to receive text in the Input area of the console. Enter must be pressed before the text is accepted.

print()

This function operates like io.write(), but moves the Output area of the console to a new line after displaying.

..

This function concatenates data items together.

age, name

These are local Lua variables used to store the information you entered in the Input area of the console.

 

Hopefully you can see how simple Lua is to write and how useful these commands are when developing and debugging Lua scripts.

Obviously you do not want to use print, io.read and io.write in operational Lua scripts assigned to GoFlight modules as its wastes CPU resources and could cause the appearance of a lockup if io.read() is used as the Lua script will wait for data from the Input area of the console.

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.