Attract-Mode Support > Scripting

Last Played Games - Most recent Games list

<< < (2/2)

spud1:
Unfortunately, I don't know.  I'm using a Raspberry Pi 3B.

spud1:
Final version of script LastPlayedGames.nut (to be added to /home/pi/.attract/plugins/):


--- Code: ---// This plugin saves the most recently played game to the "Last_Played_Games.txt" romlist
fe.add_transition_callback( "most_recent_game" );
function most_recent_game( ttype, var, ttime )
{
 switch ( ttype )
 {
  case Transition.ToGame:
                system( "echo '" + fe.game_info( Info.Name ) + ";" + fe.game_info( Info.Title ) + ";" + fe.game_info( Info.Emulator ) + ";" + fe.game_info( Info.CloneOf ) + ";" + fe.game_info( Info.Year ) + ";" + fe.game_info( Info.Manufacturer ) + ";" + fe.game_info( Info.Category ) + ";" + fe.game_info( Info.Players ) + ";" + fe.game_info( Info.Rotation ) + ";" + fe.game_info( Info.Control ) + ";" + fe.game_info( Info.Status ) + ";" + fe.game_info( Info.DisplayCount ) + ";" + fe.game_info( Info.DisplayType ) + ";" + fe.game_info( Info.AltRomname ) + ";" + fe.game_info( Info.AltTitle ) + ";" + fe.game_info( Info.Extra ) + ";" + fe.game_info( Info.Buttons ) + "' >> ~/.attract/romlists/Last_Played_Games.txt" ); // Takes the details of the game most recently played and inserts them at the end of the Last_Played_Games.txt romlist
                system( "tac ~/.attract/romlists/Last_Played_Games.txt | awk 'NR==1 {a=$0; next} 1; END{print a}' | tac > ~/.attract/romlists/Last_Played_Games1.txt && rm ~/.attract/romlists/Last_Played_Games.txt && mv ~/.attract/romlists/Last_Played_Games1.txt ~/.attract/romlists/Last_Played_Games.txt" ); // Takes the most recently played game and moves it to the start of the romlist
                system( "awk '!x[$0]++' ~/.attract/romlists/Last_Played_Games.txt > ~/.attract/romlists/Last_Played_Games1.txt && rm ~/.attract/romlists/Last_Played_Games.txt && mv ~/.attract/romlists/Last_Played_Games1.txt ~/.attract/romlists/Last_Played_Games.txt" ); // Removes duplicate entries in the romlist, leaving only the first (and most recent) entry for a particular game
        return false;
}}

--- End code ---

To ensure that the focus is on the most recent game that was played when the Most Recently Played Game Display is first opened, add the following code to the layout.nut of the Display/Theme:


--- Code: ---// This plugin ensures that when the Most Recent Games Display is opened, the first game in the romlist is in focus
fe.add_transition_callback( "first_game" );
function first_game( ttype, var, ttime )
{
 switch ( ttype )
 {
  case Transition.ToNewList:
    fe.list.index = 0
        return false;
}}

--- End code ---

Thanks to keilmillerjr for help on the above script.

Navigation

[0] Message Index

[*] Previous page

Go to full version