Author Topic: Script for export name game or system  (Read 8060 times)

Mayki07

  • Full Member
  • ***
  • Posts: 31
    • View Profile
Script for export name game or system
« on: August 31, 2018, 09:19:10 AM »
Could someone write a script or plugin for Linux (Raspberry Pi) that would export the name of the selected game or system to a separate txt file?
I would need it to display the information or marquee on the additional LED Matrix panel.

https://github.com/hzeller/rpi-rgb-led-matrix

If you can help me, I'll be very grateful ...

Favdeacon

  • Sr. Member
  • ****
  • Posts: 129
    • View Profile
Re: Script for export name game or system
« Reply #1 on: September 02, 2018, 12:11:46 AM »
Alas, I can't help you directly, but if you don't get answers here soon, you could ask in a suitable forum for your Linux variant, e.g. the Gaming and Raspbian sections of the official Raspberry Pi forum, or in the official Retropie forum, if you're using that.

Mayki07

  • Full Member
  • ***
  • Posts: 31
    • View Profile
Re: Script for export name game or system
« Reply #2 on: September 02, 2018, 01:10:08 AM »
Thank you for trying to help.
In the Retropie forum I have already asked, it seems like no one knows how to do it. It's only by using the runcommand-onstart script, but it will select the game name or marquee until the game starts, not when choosing what I want. I'm not a programmer, but I thought it could somehow go through Attractmode and layout.nut and the fe.add or another command ...  :'(

I'm building the Arcade Cabinet and I wanted to use the glossy LCD Matrix screen to display the Marquee or Game name. Perhaps it can solve it somehow.

raygun

  • Administrator
  • Sr. Member
  • *****
  • Posts: 393
    • View Profile
Re: Script for export name game or system
« Reply #3 on: September 02, 2018, 10:03:58 AM »
The following code will write the current game name to "/.attract/current_name.txt", the current game title to "/.attract/current_title.txt", and the current system to "/.attract/current_system.txt".  Hopefully this will get you started, you can paste this into a new plugin or just as part of your layout script....

Code: [Select]
fe.add_transition_callback( "gamename_transition" );
function gamename_transition( ttype, var, ttime )
{
        if (( ttype == Transition.EndNavigation )
                || ( ttype == Transition.StartLayout ))
        {
                system( "echo '" + fe.game_info( Info.Name ) + "' > ~/.attract/current_name.txt" );
                system( "echo '" + fe.game_info( Info.Title ) + "' > ~/.attract/current_title.txt" );
                system( "echo '" + fe.game_info( Info.System ) + "' > ~/.attract/current_system.txt" );
        }
        return false;
}

cheers

Mayki07

  • Full Member
  • ***
  • Posts: 31
    • View Profile
Re: Script for export name game or system
« Reply #4 on: September 02, 2018, 10:41:56 AM »
Thank you very much, it works perfectly...  ;D ;D ;D

Favdeacon

  • Sr. Member
  • ****
  • Posts: 129
    • View Profile
Re: Script for export name game or system
« Reply #5 on: September 02, 2018, 11:47:16 AM »
A final thought: You may want to write the file to the ram disk /dev/shm to avoid constant disk writes while browsing the games list.

Mayki07

  • Full Member
  • ***
  • Posts: 31
    • View Profile
Re: Script for export name game or system
« Reply #6 on: September 02, 2018, 11:53:14 AM »
Can you specify this? I'm not avoiding new ideas.

Favdeacon

  • Sr. Member
  • ****
  • Posts: 129
    • View Profile
Re: Script for export name game or system
« Reply #7 on: September 02, 2018, 12:22:20 PM »
The simplest way would be to change the path in raygun's code from "~/.attract/current_name.txt" to "/dev/shm/current_name.txt". The rest depends on how you process the file further for your LED panel. In a nutshell, you would only have to change the path wherever it is used or create a soft link to the file from its former location. (I can tell you how if you need it.)

Remember though that the contents of a ramdisk won't survive a reboot, so there wouldn't be an initial file before AM writes it again. That may cause problems if the LED code isn't prepared for a missing file. You could create one at boot time with this command:

Code: [Select]
echo "Retropie" > /dev/shm/current_name.txt
(Change "Retropie" to whatever you want to be in the initial current_name.txt.)

In Retropie, you can put this line at the start of the file /opt/retropie/configs/all/autostart.sh ahead of any other commands there to execute it at boot time.

Mayki07

  • Full Member
  • ***
  • Posts: 31
    • View Profile
Re: Script for export name game or system
« Reply #8 on: September 02, 2018, 12:30:39 PM »
Thank you for the explanation.
How to make a soft link to the file from its former location?

Favdeacon

  • Sr. Member
  • ****
  • Posts: 129
    • View Profile
Re: Script for export name game or system
« Reply #9 on: September 02, 2018, 12:51:33 PM »
Code: [Select]
ln -s /dev/shm/current_name.txt ~/.attract/current_name.txt
Whereby /dev/shm/current_name.txt is the actual file and ~/.attract/current_name.txt is the symbolic link (symlink, soft link).

All writing directed to the link will actually be done to the file.

Favdeacon

  • Sr. Member
  • ****
  • Posts: 129
    • View Profile
Re: Script for export name game or system
« Reply #10 on: September 02, 2018, 10:26:36 PM »
Remember though that the contents of a ramdisk won't survive a reboot, so there wouldn't be an initial file before AM writes it again. That may cause problems if the LED code isn't prepared for a missing file.

That still applies to the symlink method. If the link points to a non-existing file, reading the link will still produce the error "no such file or directory" like reading from the missing file directly. Writing will work normally, though. If something writes to the link, a missing target file will be created automatically.

So, you will still need to create the file at boot time if its absence causes problems. (But only then.)


Mayki07

  • Full Member
  • ***
  • Posts: 31
    • View Profile
Re: Script for export name game or system
« Reply #11 on: September 03, 2018, 12:46:27 AM »
Thanks for your help, let me know how it works. ;)

Mayki07

  • Full Member
  • ***
  • Posts: 31
    • View Profile
Re: Script for export name game or system
« Reply #12 on: September 06, 2018, 12:07:17 PM »
The following code will write the current game name to "/.attract/current_name.txt", the current game title to "/.attract/current_title.txt", and the current system to "/.attract/current_system.txt".  Hopefully this will get you started, you can paste this into a new plugin or just as part of your layout script....

Code: [Select]
fe.add_transition_callback( "gamename_transition" );
function gamename_transition( ttype, var, ttime )
{
        if (( ttype == Transition.EndNavigation )
                || ( ttype == Transition.StartLayout ))
        {
                system( "echo '" + fe.game_info( Info.Name ) + "' > ~/.attract/current_name.txt" );
                system( "echo '" + fe.game_info( Info.Title ) + "' > ~/.attract/current_title.txt" );
                system( "echo '" + fe.game_info( Info.System ) + "' > ~/.attract/current_system.txt" );
        }
        return false;
}

cheers

Is there a command that would run a bash script when choosing a system or game?
Thank you for your help.