Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't get Lua example scripts to work
#1
I'm trying to create a Lua script to alter keys in the midst of gameplay (specifically for the game Kingdom Hearts - Chain of Memories), but I can't seem to get any of the Lua scripts to work at all. I downloaded some from the GitHub repo and loaded them in the `Tools -> Scripting` window, but if I try to run them while a game is playing they'll throw errors like "attempt to index a nil value (global 'input')" for `analog-interpolate` and `gamepad-demo`, or "attempt to index a nil value (global 'image')" for `color-mask`.

Is there something I'm missing here, like a script you need to run beforehand to set up these global variables, or am I only supposed to run these against an example ROM or something? I've tried for over an hour now to find documentation, but all I can find is the Scripting API and the example Lua snippets. Would greatly appreciate any help or advice.
Reply

#2
Those examples only work on mGBA 0.11 dev builds because they use features that were added after 0.10. The demo scripts that work with 0.10 are the ones distributed with the program.
Reply

#3
(08-04-2024, 08:59 AM)endrift Wrote: Those examples only work on mGBA 0.11 dev builds because they use features that were added after 0.10. The demo scripts that work with 0.10 are the ones distributed with the program.

Thank you!
Reply

#4
(08-04-2024, 08:59 AM)endrift Wrote: Those examples only work on mGBA 0.11 dev builds because they use features that were added after 0.10. The demo scripts that work with 0.10 are the ones distributed with the program.

Hey! Kind of piggy backing here, but I've just recently gotten into lua, and for the most part I can't seem to get past the nil value issue when trying to access memory. Im using the dev build for 0.11, I can confirm the Lua version installed, do silly things like hello world and what not, but for instance when I try to access and read from memory im met with "attempt to index a nil value (global 'memory')
``` > local value = memory.readbyte(0x02000000) -- Test address
print("Value at 0x02000000: " .. value)```

or when trying to see if I have access to memory at all,
```
if memory then
print("Memory functions are available!")
else
print("Memory functions are NOT available.")
end
```
which always returns my else case. Sorry to be a pest, I don't really know what im doing in all honesty lol.


Attached Files
.png   Screenshot 2025-02-27 050059.png (Size: 11.59 KB / Downloads: 0)
Reply

#5
Those are the BizHawk functions. The names are different in mGBA: https://mgba.io/docs/dev/scripting.html#...Core.read8 So you'd need to call
Code:
emu:read8(0x02000000)
instead.
Reply

#6
(02-27-2025, 11:12 PM)endrift Wrote: Those are the BizHawk functions. The names are different in mGBA: https://mgba.io/docs/dev/scripting.html#...Core.read8 So you'd need to call
Code:
emu:read8(0x02000000)
instead.

Thank you for the quick response! I'll give it a shot, much appreciated Big Grin
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

Powered By MyBB, © 2002-2025 Melroy van den Berg.