MAMEWorld >> Programming
Previous thread Previous  View all threads Index   Next thread Next   Threaded Mode Threaded  

Pages: 1

Yugffuts
MAME Fan
Reged: 05/09/07
Posts: 90
Loc: NJ
Send PM


LUA Script Help (trying to insert a coin)
#394820 - 09/24/22 09:04 PM


Hi,

I'm trying to poke around with the LUA system but frankly I'm not making much progress. I would love to have a code example for inserting a coin on a given machine. Does anyone know where I should be looking or perhaps can provide an example here?

I have been leaning on https://docs.mamedev.org/techspecs/luaengine.html & https://docs.mamedev.org/techspecs/luareference.html but it's just not clicking for me.

Thanks.



Vas Crabb
BOFH
Reged: 12/13/05
Posts: 4462
Loc: Melbourne, Australia
Send PM


Re: LUA Script Help (trying to insert a coin) new [Re: Yugffuts]
#394822 - 09/25/22 12:17 AM


There are two included plugins that manipulate inputs:


See if you can work something out.



Yugffuts
MAME Fan
Reged: 05/09/07
Posts: 90
Loc: NJ
Send PM


Re: LUA Script Help (trying to insert a coin) new [Re: Vas Crabb]
#395162 - 11/18/22 01:53 AM


All right, I found "function lib:load_settings()" in autofire_save.lua which appears to be what I was looking for (identifying the machine buttons), so thanks for that!

Unfortunately, I'm seeing errors when attempting to require JSON from the console.


Code:


D:\MAME>mame64_247 mk -window -console -sound none

mame 0.247
Copyright (C) Nicola Salmoria and the MAME team

Lua 5.3
Copyright (C) Lua.org, PUC-Rio

[MAME]> local json = require('json')
[MAME]> print(json.stringify("{'test': 555}"))
error: [string "..."]:2: attempt to index a nil value (global 'json')
[MAME]>



Am I doing something wrong? Does "require" not work from the command line?



Vas Crabb
BOFH
Reged: 12/13/05
Posts: 4462
Loc: Melbourne, Australia
Send PM


Re: LUA Script Help (trying to insert a coin) new [Re: Yugffuts]
#395165 - 11/18/22 07:23 AM


Each line you type on the console is effectively run as a function. This means that any local variables will only persist until the end of that line. The json variable you created no longer existed when you tried using it.



Yugffuts
MAME Fan
Reged: 05/09/07
Posts: 90
Loc: NJ
Send PM


Re: LUA Script Help (trying to insert a coin) new [Re: Vas Crabb]
#395169 - 11/18/22 04:19 PM


Thank you Vas!!

It seems I had a few issues there, overlooking "local" and also my JSON test was not the right syntax

This works as intended.

Code:


json=require('json')
print(json.stringify("{'test':'555'}"))



Pages: 1

MAMEWorld >> Programming
Previous thread Previous  View all threads Index   Next thread Next   Threaded Mode Threaded  

Extra information Permissions
Moderator:  Pi 
0 registered and 21 anonymous users are browsing this forum.
You cannot start new topics
You cannot reply to topics
HTML is enabled
UBBCode is enabled
Thread views: 279