b.gauthier
Posts: 4
Joined: Wed Aug 30, 2017 7:33 am

Plugin MAME

Hello,

On lua script (plugin MAME), i try to understand the logic. I create a simple plugin to write a file with “test”. (no wiki :( )

Code: Select all

-- test.lua
-- by XXXX
--
--
local exports = {}
exports.name = "test"
exports.version = "1.0.0"
exports.description = "Test"
exports.license = "NewQuest"
exports.author = { name = "XXXX" }
local test = exports

function test.startplugin()
 local test_path = "test";

 local function get_file_name ()
  local r;
  if emu.softname() ~= "" then
   r = test_path .. '/' .. emu.romname() .. "_" .. emu.softname() .. ".txt";
  else
   r = test_path .. '/' .. emu.romname() .. ".txt";
  end
  return r;
 end

 emu.print_verbose("test: init")
 emu.print_verbose(get_file_name())
 local output = io.open(get_file_name(), "wb");

 if not output then
  -- attempt to create the directory, and try again
  lfs.mkdir( test_path );
  output = io.open(get_file_name(), "wb");
 end

 output:write("test");
 output:close();
end

return exports
this plugin don’t work
Where is display “emu.print_verbose” ?
On plugin.json, option “start” : true/false What's the point?
If i set start:true on my test plugin, MAME can not play games
If i set start:false on my test plugin : it’s ok but a file don’t created
And if start:false when plugin is executed ?

Thanks for you help
Last edited by b.gauthier on Fri Sep 01, 2017 5:56 pm, edited 1 time in total.
b.gauthier
Posts: 4
Joined: Wed Aug 30, 2017 7:33 am

Re: Plugin MAME

Where is display “emu.print_verbose” ?
=> I don't find but with print function, it's OK

On plugin.json, option “start” : true/false What's the point?
=> it's OK : if true : auto start plugin :)

If i set start:true on my test plugin, MAME can not play games
=> simply a error on my script, use emu.romname() too early

Thanks
b.gauthier
Posts: 4
Joined: Wed Aug 30, 2017 7:33 am

Re: Plugin MAME

I update my questions :

- Where is display “emu.print_verbose” ?
- Are there events ? rom launched for example ?

Thanks
b.gauthier
Posts: 4
Joined: Wed Aug 30, 2017 7:33 am

Re: Plugin MAME

can help other people :

it is an example of a code that works, with a action on start of a game (inspired by hiscore plugin)

Code: Select all

-- test.lua
-- by XXXX
--
--
local exports = {}
exports.name = "test"
exports.version = "1.0.0"
exports.description = "Test"
exports.license = "XXX"
exports.author = { name = "XXX" }
local test = exports

function test.startplugin()
 print('=>OKOK');

 print("test: init")


 local last_write_time = -10;
 local function tick ()
  if emu.time() > last_write_time + 5 then
    print("test:tick");
   last_write_time = emu.time();
  end
 end

 local function reset()
   print("test:reset");
 end

 emu.register_start(function()
  print("Starting " .. emu.gamename());
  last_write_time = -10
 end)

 emu.register_frame(function()
  tick();
 end)

 emu.register_stop(function()
  reset()
 end)

 emu.register_prestart(function()
  reset()
 end)

end

return exports

Return to “MAME Discussion”