# Getting Started

Using Lua scripting

Lua is built into FCEUX as of 2.1.2, and luapack DLL files are no longer needed in this and later versions.

To run lua scripts in older versions of FCEUX, you will need the lua pack which can be found here. The .dll files must be unzipped in the same folder as fceux.exe.

Core Lua Documentation

If you have never programmed, you will probably want to start by learning the basic of Lua, which is too broad for the scope of this help file. Try searching on the Internet for "Lua tutorial". As of this writing, it's official homepage is http://www.lua.org/

If you are familiar with any programming language you will probably not have too much difficulty adjusting to the syntax and structure of Lua. You will probably also find useful information on the Internet.

GUI Frontend

To use a Lua script, you need to create one in a text editor. The name of the file created should end in .lua to indicate that it is a Lua script.

To run a Lua script, choose "Run Lua Script" ***from where*** In the dialog that pops up, click "Browse" and find the file you wish to run. This will insert the path of this file into the dialog. You can then click on "Run" to run the script or "Cancel" to return to FCEUX without running the script.

To end a Lua script, choose "Stop Lua Script" ***from where***.

FCEUX Lua Basics

Your script will be constructed according to the rules of Lua, but you will use FCEUX-specific functions to interact with the emulator. For example, one of the most often-used functions is emu.frameadvance() which will tell the emulator to advance exactly one frame, which is the basic unit of time on an NES.

In general, your script will probably want to be run until you tell it to stop, so it will look something like this:

emu.speedmode("normal") -- Set the speed of the emulator

-- Declare and set variables or functions if needed

while true do

-- Execute instructions for FCEUX

emu.frameadvance() -- This essentially tells FCEUX to keep running

end

The way instructions are sent to FCEUX is through a set of specially defined functions (and variables) which are called an API, the specification of which follows.

Created with the Personal Edition of HelpNDoc: Easily create Help documents