Build scripts with AI — step by step
A complete beginner walkthrough for Cursor, OpenCode, Codex, Devin, MCP, Hello World, and AI-assisted testing.
You can describe what you want in ordinary language and let an AI assistant write the Lua code. This guide takes you from installing an assistant to running your first script and asking the assistant to test its own changes. No programming experience is required.
Your first goal: create a script that writes Hello World to the Sharp Scripts log, then a small module that the AI can start, observe, reload, and stop. Choose one assistant; you do not need all four.
1. Understand the few words you will see
| Word | Meaning in this guide |
|---|---|
| AI assistant | The tool you talk to, such as Cursor or Codex. “IA” means the same thing. |
| Prompt | The message you send the AI describing a task. |
| Script | A text file containing instructions written in Lua. |
| Lua | The scripting language Sharp runs. Sharp uses Lua 5.5.1. |
| SDK | The supported helpers and documentation available to scripts. |
| API | A named function your script can use, such as log.info. |
| Module | A script that stays loaded until you stop it. |
| Instant script | A script that runs once and finishes. |
| MCP | A connection that gives an AI tools to read script status, save scripts, run them, and read their logs. |
| Log | A record of messages and errors produced by a script. |
| Terminal | A window where you paste a command and press Enter. PowerShell is a Windows terminal. |
| Local | Running on your own PC. |
| Reload | Stop the previous Lua state and start again using the saved files. |
The workflow is:
You describe a goal
→ AI reads the documentation
→ AI writes a Lua script
→ MCP sends a run or reload request to Sharp
→ Sharp executes it
→ AI reads fresh status and logs
→ AI fixes problems and reports what actually passedThe documentation tells the AI how to write scripts. MCP lets it try them. Giving the AI a documentation link alone does not connect it to your game.
2. Choose an assistant
| Assistant | How you use it | Live testing on your PC |
|---|---|---|
| Cursor | An editor with files and an AI chat side by side | Use its local Agent with the MCP connection below. |
| OpenCode | An AI coding tool; this guide uses its Windows terminal version | Use it directly in Windows PowerShell with local MCP. |
| Codex | OpenAI’s coding assistant; this guide covers local app, extension, and CLI setup | Use a local execution environment on the game PC. |
| Devin | A hosted coding assistant | Use it to prepare code and tests; hand live testing to a local assistant. |
For this walkthrough, Cursor is convenient if you prefer clicking through an editor. Codex and OpenCode also work when configured locally. Use the tool and account you already have if possible. AI providers may require a subscription or paid usage; check their account page before adding billing.
About localhost: 127.0.0.1 means “this computer.” In a cloud session,
container, remote computer, or separate Linux environment, it can point to a
different computer than your Windows game. The simplest setup is a Windows AI
client and Sharp running on the same PC. Keep the game MCP on loopback; do not
make it public to connect a cloud assistant.
3. Prepare Sharp and your script folder
- Start AION 2 and Sharp through your normal workflow. Enter the game and open Sharp’s Scripts tab.
- Find the Scripts folder shown in the tab’s folder tooltip. Sharp normally
uses
Atreia/Scriptsinside your Windows Documents folder. Documents can be redirected, so use the folder Sharp actually shows. - Open that folder in Windows File Explorer. Keep it open for later steps.
- In the Scripts tab, click Download latest SDK. This installs libraries
under
lib; it does not start a script. - Make a backup of any script you plan to edit. Use a new name such as
hello_aifor this tutorial so an existing script is not overwritten.
Inside the resolved Scripts folder you will use:
Scripts/
instant/
hello_ai.lua ← first, one-time script
modules/
hello_ai_module/
main.lua ← second, persistent script
lib/ ← downloaded SDK helpers
logs/ ← messages and errorsSee script types and the manual quickstart if you want to try the Scripts tab first. You do not need the C++ project or a compiler to write customer Lua scripts.
Open PowerShell and check Python
- Open the Windows Start menu, type PowerShell, and open it normally.
- Paste this command and press Enter:
python --versionYou need Python 3.10 or newer for the MCP adapter. If Python is missing, install it from python.org, enable the installer option to add Python to PATH, and reopen PowerShell. PATH is how Windows finds a program when you type its name.
Install the adapter’s required Python package:
python -m pip install --upgrade "mcp>=2.2,<3"Wait for the command to finish successfully. If the installer offers Windows changes you do not understand, ask the AI to explain the message first. You do not need to run the AI or PowerShell as Administrator for the loopback protocol.
Start the MCP HTTP adapter
- Return to Sharp’s Scripts tab.
- Check the game-side MCP bridge indicator. It should show Ready.
- Click Restart MCP HTTP to start or refresh the supplied Python adapter.
- Wait for Restarted. If it shows Failed, hover over the result and read the full message. Fix that error before continuing.
Sharp builds with the embedded adapter install its files into the Scripts folder when you click the button. You do not need to copy files beside the DLL. If the tooltip says launcher assets are missing beside the DLL, the loaded Sharp build predates this fix; update through the normal Sharp launcher workflow.
The address to give the AI client is:
http://127.0.0.1:38472/mcpUse the complete address, including /mcp. Choose Streamable HTTP when
a client asks for a transport. Do not select the older SSE transport.
The HTTP adapter and the game-side bridge are two separate pieces. Restart MCP HTTP refreshes the Python adapter. Restart MCP bridge reconnects the game-side listener. Neither button reloads your Lua modules.
If these controls are missing, update Sharp through its normal release workflow and check again. Installing Python alone cannot add a missing client feature. Do not start duplicate adapters or stop an unidentified process using the port.
4. Set up Cursor
- Download and install Cursor from cursor.com. Sign in.
- Choose Open Folder and open the actual Scripts folder from step 3.
- Open the AI chat and choose Agent so it can edit files and use tools.
- In that folder, create a directory named
.cursor, then createmcp.jsoninside it. If the file exists, add this server to its existingmcpServersobject instead of replacing your other connections. - Save this configuration:
{
"mcpServers": {
"game-mcp": {
"url": "http://127.0.0.1:38472/mcp"
}
}
}- Open Cursor’s MCP settings and enable
game-mcp. If necessary, reopen the window to refresh the configuration. - Approve the initial read-only tool call when Cursor requests it. Continue to the connection check in step 8 below.
This is a project configuration: opening a different folder may use different
MCP settings. The file must be named mcp.json, not mcp.json.txt.
Cursor documents this setup in its official MCP guide.
5. Set up OpenCode
This example uses the OpenCode 1 configuration documented at the links below. If you already use OpenCode 2, follow its migration documentation rather than installing another version over it.
- Install the LTS version of Node.js.
Reopen PowerShell and check
node --versionandnpm --version. - Install OpenCode:
npm install -g opencode-ai- In File Explorer, open your Scripts folder, click the address bar, type
powershell, and press Enter. This opens a terminal in that folder. - Create
opencode.jsonin the Scripts folder, using:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"game-mcp": {
"type": "remote",
"url": "http://127.0.0.1:38472/mcp",
"enabled": true,
"oauth": false
}
}
}- Run
opencode. Use/connectto sign in to your chosen AI provider. Enter credentials in the provider setup, not in your Lua file or a chat message. - Use Build mode for editing and tool execution. Plan mode is for discussing changes. Restart OpenCode after changing its MCP configuration if needed.
- Run
opencode mcp listin PowerShell to inspect connections, then perform step 8 in the AI chat.
Here type: "remote" means an HTTP connection; its URL still points to your
own PC. The adapter handles the game session authentication, so this connection
does not need an OAuth login or a copied game token.
Use native Windows PowerShell for this walkthrough to avoid a separate WSL
network environment.
Sources: OpenCode setup and
OpenCode MCP configuration.
6. Set up Codex
Use Codex locally on the game PC. A hosted coding task cannot reach this PC’s loopback URL merely because you paste it into a prompt.
Local app or IDE extension
- Install your preferred local Codex interface from the official Codex documentation. Sign in and open your Scripts folder.
- Select a local execution environment. In the IDE extension, open the gear menu, then MCP servers → Add server.
- Name it
game-mcp, select Streamable HTTP, and enterhttp://127.0.0.1:38472/mcp. Save and restart the extension. - If your interface has no matching setup control, add the following table to
your user-level
.codex/config.tomlfile. On Windows this is in your Windows user folder. Preserve existing settings:
[mcp_servers.game-mcp]
url = "http://127.0.0.1:38472/mcp"- Start a new local chat and use the connection-check prompt in step 8.
CLI alternative
With Codex CLI already installed, open PowerShell in your Scripts folder:
codex mcp add game-mcp --url http://127.0.0.1:38472/mcp
codex mcp list
codexUse /mcp inside the CLI to inspect active connections. Installation and
sign-in instructions are in the CLI guide.
Configuration details are in the official MCP guide.
7. Set up Devin and hand off live testing
Devin can help write code and offline tests using the documentation you provide. Its hosted environment has a different localhost from your Windows game PC. For this guide, use Devin to prepare the files and a local assistant to execute the live tests.
- Sign in at Devin and create a coding session.
- Provide your script files through your normal project or file workflow. Give it the documentation links and the starter prompt in step 9.
- Tell Devin to return the Lua files, offline test results, installation instructions, and a checklist for local testing. Do not claim live success.
- Save the returned files under the correct Scripts folder on your Windows PC.
- Open that folder in Cursor, OpenCode, or local Codex. Connect MCP and paste the handoff prompt below.
Review this script prepared by Devin using the Sharp Lua documentation.
The intended module ID is hello_ai_module.
Check the saved code first. Then use game-mcp to call scripts_list,
inspect the available tools, and test only this module.
Report fresh runtime evidence separately from Devin's offline tests.
Do not change or restart other scripts.For other reachable MCP services, Devin’s official setup is Customize → MCPs → Add MCP → Add custom MCP, choose the transport, enter its details, save, then use Test tools for HTTP/SSE. Custom setup needs the appropriate organization permission. This does not make the local Sharp endpoint reachable from Devin. See Devin MCP setup.
8. Check the connection before writing a script
Paste this into your local AI assistant:
Check my Sharp game-mcp connection without changing anything.
Discover the available MCP tools and call scripts_list first.
If it succeeds, call scripts_catalog or scripts_modules.
Tell me which scripts are available and whether the game-side connection works.
Do not start, reload, stop, or edit any script during this check.
If a call fails, explain the exact error and stop before any action.What success looks like: the AI reports a successful scripts_list result,
then the available scripts. An empty list can be normal before your first
script. A green connection icon or a discovered tool list alone does not prove
communication with the game.
| Result | What it proves |
|---|---|
| MCP configuration saved | The client has an address to try. |
| Tools discovered | The adapter can describe its tools. |
scripts_list succeeds | A request reached the authenticated game-side service. |
| Run/load says queued | A request was accepted for a later game tick. |
| Fresh expected log appears | Lua actually reached that logging step. |
| You see the expected UI or game result | The visible behavior was checked too. |
You do not need to open bridge.txt or copy its contents. It contains a secret
session token that the adapter reads automatically. Do not paste it into chat.
9. Teach the AI to use this documentation
Start each new script chat with this prompt. Replace the goal and script ID when you move beyond Hello World:
I am a beginner building a Sharp Aion2 Lua 5.5.1 script.
Documentation: https://sharp-aion2-lua-docs.pages.dev/docs/
Quickstart: https://sharp-aion2-lua-docs.pages.dev/docs/quickstart/
AI guide: https://sharp-aion2-lua-docs.pages.dev/docs/guides/ai-scripting/
API reference: https://sharp-aion2-lua-docs.pages.dev/docs/reference/
Read the relevant pages before writing code. Tell me which documented
functions you will use. If you cannot open a page, ask me to paste its content.
Do not invent API names or treat Game SDK method declarations as callable helpers.
Explain each step in plain language and show the exact file location.
Use game-mcp only after a successful read-only scripts_list.
Check the available tools and their argument schemas before calling them.
Work only on my requested script, preserve a backup before replacing it,
and confirm fresh logs after running or reloading it.
Keep offline checks, queued requests, runtime logs, and visible results separate.
If a run or reload times out, inspect status and logs; do not repeat the action.
My first goal: create and test an instant script named hello_ai
that logs Hello World. It must not change anything in the game.The AI may need permission to fetch web pages, edit files, or use an MCP tool. Read the proposed action and approve the action you requested. A client that cannot fetch a page can still work if you copy the relevant page text into the chat. A URL that the AI has not read is insufficient context.
Find the right page together
- Open the documentation search and type a topic such as log, window, character, or state.
- Open a result and read its parameters, returned values, and example.
- Copy the page link into the AI chat and say which behavior you want.
- Ask the AI to explain what happens if that function returns
nil, error. - For a larger task, give it a working example from the examples guide to adapt.
Start with the supported API reference. The Game SDK browser also contains game declarations: a listed method does not automatically mean your Lua script can call it. Ask the AI to use a documented callable helper or a supported getter example.
10. Make your first Hello World
The complete instant script is one line:
log.info("Hello World")log.info writes a message. The quoted text is the message to print.
This sample needs no imported library and no character data.
Let the AI save and run it
After the connection check, paste:
Create the instant script hello_ai containing log.info("Hello World").
Use scripts_write_instant to save it, then scripts_run_file to run it once.
Use the exact tool schemas advertised by my adapter.
After a game tick, read scripts_logs with id hello_ai and kind instant.
Confirm a NEW Hello World entry after this run, not a line from an earlier run.
Show me the result and saved location. Do not rerun it automatically.The tool arguments for the saved-script path are:
{
"id": "hello_ai",
"source": "log.info(\"Hello World\")"
}Use that object with scripts_write_instant, then {"id":"hello_ai"}
with scripts_run_file. Read the log using:
{
"id": "hello_ai",
"kind": "instant"
}These are tool arguments for the AI, not commands to paste into PowerShell.
An ID is the short script name, without folders or .lua.
scripts_run_instant can also execute supplied source once; saving with
scripts_write_instant makes a file you can find and run again later.
Manual fallback
- In your resolved Scripts folder, open or create
instant. - Save the one-line sample as
hello_ai.luausing the editor. In Notepad’s Save as dialog, select All files so it does not add.txt. - In Sharp’s Scripts tab, click Refresh, select
hello_ai, then Run. - Look for Hello World in its log or
logs/instant_hello_ai.log.
The message appears in the script log, not the game chat. Old log entries can remain between runs; compare the newest entry’s time with your test. If the AI cannot read MCP logs, this is a manual result you report back to it.
11. Make a module the AI can watch
An instant script finishes too quickly to demonstrate a running lifecycle.
Create modules/hello_ai_module/main.lua with this full sample:
local elapsed = 0
local heartbeatCount = 0
function on_start()
log.info("Hello World module started — test v1")
end
function on_tick(dt)
if heartbeatCount >= 3 then
return
end
elapsed = elapsed + dt
if elapsed >= 2 then
elapsed = 0
heartbeatCount = heartbeatCount + 1
log.info("Heartbeat " .. heartbeatCount .. "/3 — test v1")
end
end
function on_stop()
log.info("Hello World module stopped — test v1")
endon_start runs when the module starts. on_tick receives elapsed seconds and
checks when to print the next message. on_stop logs a normal unload.
The sample prints three heartbeats about two seconds apart, then stays loaded
quietly until you unload it. It does not move the character or send game chat.
There is no busy loop and it does not flood the log every frame.
Ask the AI:
Save the heartbeat sample from the AI guide as hello_ai_module.
Use scripts_write_module_file with id hello_ai_module, file main,
and the complete source. Load it with scripts_load once.
After a tick, check scripts_list and fresh module logs.
Over about 8 seconds, poll the module log at roughly 2-second intervals.
Expect a new start entry and Heartbeat 1/3, 2/3, and 3/3 with test v1.
Report errors or missing entries. Do not treat queued as executed.
Then unload only hello_ai_module and confirm it is no longer running.
Read the fresh stop entry too. Leave every other script alone.To write main.lua, the relevant tool object has these fields:
{
"id": "hello_ai_module",
"file": "main",
"source": "PASTE THE COMPLETE MODULE SOURCE HERE"
}The AI fills source with the complete Lua code, including newlines. The
placeholder above is not runnable Lua. Load, reload, and unload each take
{"id":"hello_ai_module"}. Logs use the same ID with "kind":"module".
Writing a file alone does not start it or replace an already running version.
12. Ask the AI to test and fix its own work
Give the AI permission to perform a specific, bounded test loop. Describe the expected result before testing so it knows what counts as success.
Test hello_ai_module and fix errors in that module only.
1. Read the relevant documentation and inspect the saved files.
2. Check Lua syntax if a compatible local checker is available.
3. Add offline tests for any calculation or decision that can be tested alone.
4. Call scripts_list before any live action, then read the existing module log
to establish which entries predate this test.
5. Save your changes, reload only hello_ai_module, and wait for a tick.
6. Watch fresh status and logs for up to 30 seconds, polling every 2 seconds.
7. If there is a Lua error, explain it, fix it, and repeat up to 3 repair cycles.
8. If an action times out or its reply is lost, do not repeat that action.
Inspect status and logs and report any uncertainty.
9. Stop only this test module when finished and confirm its stopped state.
10. Report files changed, checks run, fresh log evidence, and anything needing
my visual check. If MCP fails, stop live testing and explain the blocker.Watching means reading new evidence. MCP provides script status and log tools; it does not give the AI a video feed of your screen. For a visible window, ask the AI for a checklist you can verify, or use a separate supported screen tool in your assistant. Never infer a visible result from a queued call.
Keep the AI session active while it watches. A prompt in an ordinary chat does not create a permanent background monitor after that session ends.
Test reloads so old code cannot fool you
- Ask the AI to change every
test v1marker totest v2and save the file. - Have it call
scripts_reloadforhello_ai_moduleonce. - Check a fresh started — test v2 line and three new test v2 heartbeats.
- Unload it and check its stopped state and a fresh stopped — test v2 line.
This verifies that the saved revision actually ran. Seeing only test v1
after an edit suggests a missed save, a missed reload, or a different file.
In Sharp’s editor, Save and reload combines both steps.
Use a small test checklist
| Test | Expected evidence |
|---|---|
| First start | A fresh start marker and no Lua error |
| Repeated updates | Three numbered heartbeat messages, then no more heartbeats |
| Reload | A fresh revision marker and counters reset to 1/3 |
| Stop | Module no longer running; normal stop message |
| Other scripts | Their running state is unaffected |
| Larger script with settings | Settings survive reload only if explicitly saved |
| Missing character/world | A clear unavailable message instead of an error |
The final two checks apply when you add those features. Ask the AI to handle missing values in code and test with mock values offline; do not disconnect or restart the game just to force an error.
Optional crash recovery
For a module you deliberately want to recover after a Lua fault, the AI can
use scripts_set_crash_retries with:
{
"id": "hello_ai_module",
"maximum": 3
}Retries occur one second apart after a fault and are limited to that module.
Zero disables them. Verify crash_retries, crash_retries_used, and
crash_retry_pending in fresh scripts_list results. The setting lasts until
Sharp unloads; it does not restart the game. Manual load/reload resets the used
count, and unload cancels a pending retry. Retry settings are queued too.
Keep retries disabled while investigating a repeated error so the first error
is easy to follow. Automatic recovery does not fix the script.
13. Turn an idea into a useful script
Describe what you see, what should happen, when it should stop, and how you will recognize success. Build one feature at a time.
Build a read-only character dashboard module named my_dashboard.
Use the supported Sharp Lua API and UI SDK documentation.
Show my name and level in a small window. Refresh at most once per second.
If character data is unavailable, show Waiting for character.
Do not move, target, buy, sell, send chat, or use items.
Keep settings only if I ask for persistence.
First explain the functions and files, then implement them.
Run available offline checks, load only my_dashboard through MCP,
and read fresh logs. Give me a visual checklist to confirm the window.Useful follow-up prompts:
| Goal | What to tell the AI |
|---|---|
| Understand generated code | “Explain this script line by line using simple words.” |
| Fix an error | “Read my module’s fresh log, identify the failing line, and fix only this script.” |
| Add a control | “Add a button using the documented UI SDK. Explain what happens when I click it.” |
| Save preferences | “Use documented module state helpers; test save, reload, and restore.” |
| Prevent log spam | “Log state changes and errors, not the same value every tick.” |
| End a test | “Unload this module only and verify it stopped.” |
| Prepare sharing | “Check the Script Store guide, list dependencies, and package the complete script.” |
For each new game action, ask for the documented result check. For example, a travel request being accepted is different from the character arriving. Read lifecycle and workers, errors and limits, UI SDK, and persistent state as your script grows.
14. Troubleshoot one symptom at a time
| Symptom | What to do next |
|---|---|
python is not recognized | Install Python, enable PATH, reopen PowerShell, and check the version. |
| MCP package missing | Run the package-install command with the same Python used by the adapter. |
| Restart MCP HTTP says Failed | Hover the result, copy the error without secrets, and ask the AI to diagnose it. |
| Port 38472 already in use | Reuse a responding adapter. Do not kill an unknown listener or launch another copy. |
| AI has no script tools | Check its MCP config, enable the server, refresh the AI session, and verify it runs locally. |
Tools appear but scripts_list fails | The adapter is reachable; inspect the actual game-side error before running anything. |
| Missing discovery file | Check the actual Scripts folder and that scripting initialized in the running client. |
| Connection refused or stale endpoint | Check whether the game is still running and the bridge is Ready. Use the normal bridge control if needed; do not replay a lost script action. |
| Unauthorized session | Recheck with a fresh read-only call; the adapter reads updated session discovery automatically. Never paste its token. |
| Script did not appear | Check the folder and .lua extension, then press Refresh. |
| Error loading an imported library | Download latest SDK, check the documented import name, and reload the saved module. |
| Edited script still runs old code | Save to the correct folder, then reload that module; look for its new revision marker. |
| Run/load reply says queued but no new message | Wait for a game tick and inspect fresh logs and status. Queue acceptance alone is not a pass. |
| Run/reload timed out | Read status and logs. Do not repeat the action because it may already have been queued. |
nil or unavailable character data | Wait until the character/world is available and make the script handle missing data. |
| AI says it watched the screen using logs | Ask it to distinguish log evidence from a visual check. |
| Devin cannot connect to localhost | Hand the code to a local assistant on the game PC; leave MCP on loopback. |
Use this help prompt:
I am stuck at step [NUMBER] of the Sharp AI scripting guide.
My assistant is [NAME], running [LOCALLY / IN CLOUD].
The exact error is [PASTE ERROR WITHOUT TOKENS OR KEYS].
Explain it in simple words, check the relevant documentation,
and give me one concrete next step. Do not repeat a timed-out run/reload,
change unrelated scripts, change security settings, or restart the game.15. Finish and continue
Before calling your first tutorial complete, confirm:
- The assistant successfully called
scripts_list. hello_ai.luais saved in the correct instant folder.- A fresh Hello World log entry appeared after your run.
- The module produced its start and three heartbeat messages.
- Reloading produced the new revision marker.
- Unloading stopped only the tutorial module.
- The AI reported actual results and any checks it could not perform.
Next, adapt a working example, look up functions in the API reference, or read the Script Store guide when you are ready to share.
Client setup was reviewed against the linked official documentation on October 11, 2026. Menu names and client versions can change; use those official links when your interface differs.