Author Topic: Filter when filling an array (Solved)  (Read 2385 times)

iOtero

  • Sr. Member
  • ****
  • Posts: 414
    • View Profile
Filter when filling an array (Solved)
« on: August 01, 2018, 08:19:57 AM »
This code filled games_db array with ALL the roms in the rom path:

Code: [Select]
// games filter
local dir = DirectoryListing(system_rom_path);

local games_db = [];

// FILTER i do not know how to apply
local sel_game = "GUN";

foreach (dir_name in dir.results)
{
// strip
local f = txt.loadFile(dir_name);
local aa = [];
local i = 1;
foreach(line in f.lines)
{
// track
local a = split(line, "\\"); // split path-file for "/"
local title = strip(a.pop().slice(0, -4)); // only filename, without ext
local folder = strip(a.pop());            // path folder

aa.push(
{
"filename" : line,
"folder" : folder,
"title" : title,
  });
   i++;
}

games_db.push(aa);
}


What I need is to just fill in games_db with the rom that contain the string "GUN" in their filename.

Any suggestions?
« Last Edit: August 29, 2018, 05:09:27 AM by iOtero »
Nacer a los 15 años Una novela de iOtero

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: Filter when filling an array
« Reply #1 on: August 02, 2018, 04:59:15 AM »
I think you can just create a filter

Code: [Select]
   filter               "Gun Games"
      rule                 Title contains gun

https://github.com/mickelson/attract/wiki/Example-filters

iOtero

  • Sr. Member
  • ****
  • Posts: 414
    • View Profile
Re: Filter when filling an array
« Reply #2 on: August 03, 2018, 04:45:29 AM »
Thanks, but your idea can not be applied.
It is not the Attract-Mode database.
It's about reading the contents of a folder and filtering that data when putting them in an array: games.db  ;D
Nacer a los 15 años Una novela de iOtero

iOtero

  • Sr. Member
  • ****
  • Posts: 414
    • View Profile
Re: Filter when filling an array
« Reply #3 on: August 10, 2018, 01:27:03 PM »
Luckily i alone have found the solution, otherwise...

Code: [Select]
local dir = DirectoryListing(system_rom_path);

foreach(dir_name in dir.results)
{
if(dir_name.find(sel_game)!= null)
{

// strip m3u
local f = txt.loadFile(dir_name);
local aa = [];
local i = 1;

foreach(line in f.lines)
{
// track
local l = split(line, "\\"); // split path-file for "/"
local name = strip(l.pop().slice(0, -4)); // only filename, without ext
local folder = strip(l.pop());            // path folder
local f = split(folder, "-");
local n = split(name, "-");
local album = strip(f[1]);
local artist = strip(n[1]);
local title = strip(n[2]);

aa.push(
{
"filename" : line,
"folder" : folder,
"title" : title,
"album" : album,
"artist" : artist
});
i++;
}
music_db.push(aa);
}
}
Nacer a los 15 años Una novela de iOtero