Author Topic: Exporting Game Info on Signal Questions!  (Read 787 times)

rand0m

  • Sr. Member
  • ****
  • Posts: 208
    • View Profile
Exporting Game Info on Signal Questions!
« on: January 23, 2019, 03:24:13 AM »
Hi, I am working on a plugin which exports/ pastes gameinfo to a text file on signal (button press). I found lots of help from this thread > http://forum.attractmode.org/index.php?topic=2420.0 (#4, raygun).


The code from raygun is:
Quote
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;
}


Since I wanted the export to text on signal, I've tweaked raygun's code a bit. My code:

Quote
fe.add_signal_handler(this, "on_signal");
function on_signal( sig1 )
{
   if ( sig1 == "custom3" )
{
        system( "echo '" + fe.game_info( Info.Name ) + "' > ~/.attract/current_name.txt" );
     return true;
    }
    return false;
}

I am facing following issues with the code and can use some help from more experienced members.

1) Whenever I press the signal button, cmd flashes for a second. Is it possible to do this in background with cmd completely hidden?

2) What I am aiming for is:
  a) on signal press
  b) search if "selected" exists in text file or not
  c) if "selected" exists, do nothing.
  d) if "selected" doesn't exist add it to the end of the list.

After searching thoroughly I can't figure out if the above mentioned code is even possible in AM. In the examples I've seen search functions are being called outside AM in batch or script, while the data (game info) is from AM and can't be accessed directly via batch/ script. So I am in a quandary how to select data from within AM and use batch/ script on it - or whether the above mentioned can be done from within AM directly. Can any one please guide me in this regard?

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 939
    • View Profile
Re: Exporting Game Info on Signal Questions!
« Reply #1 on: January 23, 2019, 03:36:15 AM »
Could try this. Don’t use windows primarily, so test. Create shortcut to cmd.exe. Properties -> run -> minimized

That’s if the plugin command bg isn’t working.
« Last Edit: January 23, 2019, 03:38:10 AM by keilmillerjr »

rand0m

  • Sr. Member
  • ****
  • Posts: 208
    • View Profile
Re: Exporting Game Info on Signal Questions!
« Reply #2 on: January 23, 2019, 03:59:11 AM »
Thanks for the help, running AM though minimized cmd still creates the cmd window when using the signal.

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 939
    • View Profile
Re: Exporting Game Info on Signal Questions!
« Reply #3 on: January 23, 2019, 05:12:29 AM »
Thanks for the help, running AM though minimized cmd still creates the cmd window when using the signal.

Does this work? https://github.com/mickelson/attract/blob/master/Layouts.md#plugin_command_bg

rand0m

  • Sr. Member
  • ****
  • Posts: 208
    • View Profile
Re: Exporting Game Info on Signal Questions!
« Reply #4 on: January 23, 2019, 11:34:44 AM »
Does this work? https://github.com/mickelson/attract/blob/master/Layouts.md#plugin_command_bg

I am a bit lost here, I am running the plugin which is in AM/plugins, not calling anything outside of AM like bash script. Where exactly do I use plugin_command_bg? Within the plugin.nut itself or in the layout? And since not calling nay external script what should I put in "plugin_command_bg (??)" plugin.nut or cmd?

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 939
    • View Profile
Re: Exporting Game Info on Signal Questions!
« Reply #5 on: January 23, 2019, 12:12:49 PM »
https://ss64.com/nt/cmd.html

Within your plugin. When you want to call cmd and echo a line directing to a txt file.

Try something like this:

Code: [Select]
plugin_command_bg(“cmd.exe”, “/C ‘echo” + fe.game_info( Info.Name ) + "' > ~/.attract/current_name.txt");

rand0m

  • Sr. Member
  • ****
  • Posts: 208
    • View Profile
Re: Exporting Game Info on Signal Questions!
« Reply #6 on: January 23, 2019, 11:14:48 PM »
https://ss64.com/nt/cmd.html

Within your plugin. When you want to call cmd and echo a line directing to a txt file.

Try something like this:

Code: [Select]
plugin_command_bg(“cmd.exe”, “/C ‘echo” + fe.game_info( Info.Name ) + "' > ~/.attract/current_name.txt");

Thankyou thankyou, finally got fe.plugin_command_bg to work. The code required a little bit of tweaking, for rest of comm a working template is:
Quote
Code: [Select]
fe.plugin_command_bg("cmd.exe /C" "echo " + fe.game_info( Info.Name )+ " > ~/.attract/current_name.txt" );

This will work both in plugin and in layout (directly).

gunthermic

  • Full Member
  • ***
  • Posts: 26
    • View Profile
Re: Exporting Game Info on Signal Questions!
« Reply #7 on: January 24, 2019, 12:22:54 AM »
So you are going to release a plugin for us to use?

This would be great to use to gather info when debugging items.

rand0m

  • Sr. Member
  • ****
  • Posts: 208
    • View Profile
Re: Exporting Game Info on Signal Questions!
« Reply #8 on: January 24, 2019, 03:20:45 AM »
So you are going to release a plugin for us to use?

This would be great to use to gather info when debugging items.

i'm afraid I'm not too familiar with plugin coding so I have kept it very simple.You can copy paste following in AM\plugins\ginfo.nut (or any name but file should be .nut and placed in /plugins).

Code: [Select]
fe.add_signal_handler(this, "on_signal");
function on_signal( sig1 )
{
if ( sig1 == "custom3" )
{
     fe.plugin_command_bg("cmd.exe /C" "echo " + fe.game_info( Info.Name ) + " >> ginfo.txt" );
    }
    return false;
}

You will have to map "custom3" key from Am > setting > controls. After activating the plugin from AM > plugins whenever you press "custom3" key it will export the data to AM\ginfo.txt. You can use any game.info value instead of ( Info.Name ) to export it. The values are:

Code: [Select]
    Info.NoSort

    Info.Name
    Info.Title
    Info.Emulator
    Info.CloneOf
    Info.Year
    Info.Manufacturer
    Info.Category
    Info.Players
    Info.Rotation
    Info.Control
    Info.Status
    Info.DisplayCount
    Info.DisplayType
    Info.AltRomname
    Info.AltTitle
    Info.Extra
    Info.Favourite
    Info.Tags
    Info.PlayedCount
    Info.PlayedTime
    Info.FileIsAvailable
    Info.System
    Info.Overview
    Info.IsPaused

(from: https://github.com/mickelson/attract/blob/master/Layouts.md#game_info)

gunthermic

  • Full Member
  • ***
  • Posts: 26
    • View Profile
Re: Exporting Game Info on Signal Questions!
« Reply #9 on: January 25, 2019, 01:02:26 AM »
So you are going to release a plugin for us to use?

This would be great to use to gather info when debugging items.

i'm afraid I'm not too familiar with plugin coding so I have kept it very simple.You can copy paste following in AM\plugins\ginfo.nut (or any name but file should be .nut and placed in /plugins).

Code: [Select]
fe.add_signal_handler(this, "on_signal");
function on_signal( sig1 )
{
if ( sig1 == "custom3" )
{
     fe.plugin_command_bg("cmd.exe /C" "echo " + fe.game_info( Info.Name ) + " >> ginfo.txt" );
    }
    return false;
}

You will have to map "custom3" key from Am > setting > controls. After activating the plugin from AM > plugins whenever you press "custom3" key it will export the data to AM\ginfo.txt. You can use any game.info value instead of ( Info.Name ) to export it. The values are:

Code: [Select]
    Info.NoSort

    Info.Name
    Info.Title
    Info.Emulator
    Info.CloneOf
    Info.Year
    Info.Manufacturer
    Info.Category
    Info.Players
    Info.Rotation
    Info.Control
    Info.Status
    Info.DisplayCount
    Info.DisplayType
    Info.AltRomname
    Info.AltTitle
    Info.Extra
    Info.Favourite
    Info.Tags
    Info.PlayedCount
    Info.PlayedTime
    Info.FileIsAvailable
    Info.System
    Info.Overview
    Info.IsPaused

(from: https://github.com/mickelson/attract/blob/master/Layouts.md#game_info)

Any chance to get it reworked for a pi3?

rand0m

  • Sr. Member
  • ****
  • Posts: 208
    • View Profile
Re: Exporting Game Info on Signal Questions!
« Reply #10 on: January 25, 2019, 07:35:50 AM »
I have no experience with pi3, I assume its *nix. If so following should work:
Quote
fe.add_signal_handler(this, "on_signal");
function on_signal( sig1 )
{
   if ( sig1 == "custom3" )
   {
     fe.plugin_command_bg("cmd.exe /C" "echo " + fe.game_info( Info.Name ) + " >>  ~/.attract/ginfo.txt" );
    }
    return false;
}

1. If pi3 follows the same directory structure then this should:
a) create the ginfo.txt file if it doesn't exist  (I think following *nix convention file should be GINFO)
b) if it exists append output to its end. Using > instead of >> will overwrite the file keeping only latest output
c) You can also add other game.info items using plus sign:
Code: [Select]
fe.plugin_command_bg("cmd.exe /C" "echo " + fe.game_info( Info.Name ) + "," + fe.game_info( Info.Title ) + " >>  ~/.attract/ginfo.txt" );
(PS: My bad, Keil is right Use "bash" instead of cmd in code given above. I forgot to replace it)!!!
« Last Edit: January 25, 2019, 08:48:48 PM by rand0m »

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 939
    • View Profile
Re: Exporting Game Info on Signal Questions!
« Reply #11 on: January 25, 2019, 02:30:59 PM »
Create conditions for win Linux and Mac. Win uses cmd, Linux bash, Mac terminal (bash). Export your txt file to your plugin directory. No need to worry about directory structure. If you need help, post here and I can review and give tips, or send me the plugin and I review when day off after 3 more nights.