RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login

    Getting the rom name and emulator

    Scheduled Pinned Locked Moved General Discussion and Gaming
    pi model v3pythonscriptretropiesetup
    82 Posts 5 Posters 18.8k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      daveyman123
      last edited by

      How would i go about getting the rom/emulator name of the current game within a python script? The idea being to send the information to a display hat on the pi.

      Thanks,
      Dm123

      BuZzB 1 Reply Last reply Reply Quote 0
      • BuZzB
        BuZz administrators @daveyman123
        last edited by

        @daveyman123 https://retropie.org.uk/docs/Runcommand/#runcommand-onstart-and-runcommand-onend-scripts

        To help us help you - please make sure you read the sticky topics before posting - https://retropie.org.uk/forum/topic/3/read-this-first

        D 1 Reply Last reply Reply Quote 0
        • D
          daveyman123 @BuZz
          last edited by

          @buzz said in Getting the rom name and emulator:

          @daveyman123 https://retropie.org.uk/docs/Runcommand/#runcommand-onstart-and-runcommand-onend-scripts

          "Useful data are passed as arguments to these scripts:

          $1 - the system (eg: atari2600, nes, snes, megadrive, fba, etc).
          $2 - the emulator (eg: lr-stella, lr-fceumm, lr-picodrive, pifba, etc).
          $3 - the full path to the rom file.
          $4 - the full command line used to launch the emulator."
          

          would i use subprocess.call within python to call these commands?

          BuZzB 1 Reply Last reply Reply Quote 0
          • BuZzB
            BuZz administrators @daveyman123
            last edited by

            @daveyman123 No - you could call your python script from the bash script passing the arguments in, then when launching a game the code will be called and you can send the game name to your display etc.

            To help us help you - please make sure you read the sticky topics before posting - https://retropie.org.uk/forum/topic/3/read-this-first

            D 1 Reply Last reply Reply Quote 0
            • D
              daveyman123
              last edited by

              thank you for the replies. very much appreciated :)

              1 Reply Last reply Reply Quote 0
              • D
                daveyman123 @BuZz
                last edited by

                @buzz said in Getting the rom name and emulator:

                @daveyman123 No - you could call your python script from the bash script passing the arguments in, then when launching a game the code will be called and you can send the game name to your display etc.

                OK so i create the bash script and make it executable. inside the script i have given the command "python /path/to/myscript.py"

                I can run the bash script from terminal and it works!

                However,
                when i launch a game the script doesnt run

                again i have put the the python script in the "runcommand-onstart.sh" script and not made the script executable or added anything other than what i mentioned before

                thanks,
                DM123

                BuZzB 1 Reply Last reply Reply Quote 0
                • BuZzB
                  BuZz administrators @daveyman123
                  last edited by BuZz

                  @daveyman123 Where did you put the file ? What version of RetroPie are you running ? Please post the script (use a code block - http://commonmark.org/help/)

                  To help us help you - please make sure you read the sticky topics before posting - https://retropie.org.uk/forum/topic/3/read-this-first

                  D 1 Reply Last reply Reply Quote 0
                  • D
                    daveyman123 @BuZz
                    last edited by

                    @buzz said in Getting the rom name and emulator:

                    @daveyman123 Where did you put the file ? What version of RetroPie are you running ? Please post the script (use a code block - http://commonmark.org/help/)

                    @buzz said in Getting the rom name and emulator:

                    @daveyman123 Where did you put the file ? What version of RetroPie are you running ? Please post the script (use a code block - http://commonmark.org/help/)

                    damnit all i forgot was to put sudo! :/ its working now!

                    i guess the next question i would ask would be: how do i retrieve the information

                    in the document you provided it says "$1" will get me the emulator. but i am unsure how to use this with python

                    thanks so much for your continued help!
                    DM123

                    BuZzB cyperghostC 2 Replies Last reply Reply Quote 0
                    • BuZzB
                      BuZz administrators @daveyman123
                      last edited by BuZz

                      @daveyman123

                      python /path/to/myscript.py "$@"
                      

                      will pass all the script arguments to your python script.

                      or use

                      python /path/to/myscript.py" "$1"
                      

                      to pass a single parameter for example

                      To help us help you - please make sure you read the sticky topics before posting - https://retropie.org.uk/forum/topic/3/read-this-first

                      cyperghostC 1 Reply Last reply Reply Quote 0
                      • cyperghostC
                        cyperghost @BuZz
                        last edited by

                        @buzz Just a coding question.
                        If I use "$@" is there need to use loops to get all arguments or will all arguments pathed?
                        I used always "$1"... parameters and definated emulator=$1.

                        Can I resolve the $@ command and say emlulator=$1 romname=$2

                        What's is the better method to handle those calls?

                        BuZzB 1 Reply Last reply Reply Quote 0
                        • cyperghostC
                          cyperghost @daveyman123
                          last edited by cyperghost

                          @daveyman123
                          You can look to this >> lfl-launcher.source and see lines 33-37

                          These arguements were created by the bash-file >> create favourties.sh

                          So the bash file (Create Favourites.sh) gives arguments to binary (lfl-launcher) the first command "/home/pi/RetroPie/roms/My Favourites" was given manually.

                          BTW: There is no need to use this binary @pjft did a great job introducing favorites in our Emulations Station :D

                          D 1 Reply Last reply Reply Quote 0
                          • D
                            daveyman123 @cyperghost
                            last edited by

                            @cyperghost

                            very informative Cyperghost. Thank You. so basically retropie is written in bash or am i way off?

                            BuZzB 1 Reply Last reply Reply Quote 0
                            • BuZzB
                              BuZz administrators @daveyman123
                              last edited by

                              @daveyman123 RetroPie-Setup (the installer script etc) is written in bash and so is the launch script. Components are written in various other languages (C/C++/Python).

                              To help us help you - please make sure you read the sticky topics before posting - https://retropie.org.uk/forum/topic/3/read-this-first

                              1 Reply Last reply Reply Quote 0
                              • BuZzB
                                BuZz administrators @cyperghost
                                last edited by

                                @cyperghost I don't understand your question.

                                To help us help you - please make sure you read the sticky topics before posting - https://retropie.org.uk/forum/topic/3/read-this-first

                                cyperghostC 1 Reply Last reply Reply Quote 0
                                • cyperghostC
                                  cyperghost @BuZz
                                  last edited by cyperghost

                                  @buzz I call a python programm with $@ within runcommand. What will be the result and how does the python script "knows" how many arguments are given.

                                  So if
                                  $1 - the system (eg: atari2600, nes, snes, megadrive, fba, etc).
                                  $2 - the emulator (eg: lr-stella, lr-fceumm, lr-picodrive, pifba, etc).
                                  $3 - the full path to the rom file.
                                  $4 - the full command line used to launch the emulator

                                  can I just use romfile=$3 variable within python and I get my romfile even by using $@?

                                  BuZzB meleuM 2 Replies Last reply Reply Quote 0
                                  • BuZzB
                                    BuZz administrators @cyperghost
                                    last edited by

                                    @cyperghost "$@" is all the parameters. eg it expands to

                                    "$1" "$2" "$3" (for any parameters that exist) so it will pass all the parameters on to the python script

                                    https://stackoverflow.com/questions/4824590/propagate-all-arguments-in-a-bash-shell-script#4824637

                                    To help us help you - please make sure you read the sticky topics before posting - https://retropie.org.uk/forum/topic/3/read-this-first

                                    D 1 Reply Last reply Reply Quote 0
                                    • D
                                      daveyman123 @BuZz
                                      last edited by

                                      @BuZz
                                      @cyperghost
                                      either of you know why i would have to powercycle my entire raspberry pi to get the "Pimoroni Unicorn Hat" to work more than once i.e. it screws up and lighting is random after one scroll through?

                                      BuZzB 1 Reply Last reply Reply Quote 0
                                      • BuZzB
                                        BuZz administrators @daveyman123
                                        last edited by

                                        @daveyman123 no idea.

                                        To help us help you - please make sure you read the sticky topics before posting - https://retropie.org.uk/forum/topic/3/read-this-first

                                        1 Reply Last reply Reply Quote 0
                                        • meleuM
                                          meleu @cyperghost
                                          last edited by meleu

                                          @cyperghost said in Getting the rom name and emulator:

                                          @buzz I call a python programm with $@ within runcommand. What will be the result and how does the python script "knows" how many arguments are given.

                                          So if
                                          $1 - the system (eg: atari2600, nes, snes, megadrive, fba, etc).
                                          $2 - the emulator (eg: lr-stella, lr-fceumm, lr-picodrive, pifba, etc).
                                          $3 - the full path to the rom file.
                                          $4 - the full command line used to launch the emulator

                                          can I just use romfile=$3 variable within python and I get my romfile even by using $@?

                                          I'm not comfortable with python at all, I only learned it to tweak the joy2key tool and never used it again. But I think the answer for your question can be found here: https://docs.python.org/2/library/sys.html#sys.argv

                                          Maybe this example can answer too:

                                          [PROMPT] $ cat args.py 
                                          #!/usr/bin/python
                                          
                                          import sys
                                          
                                          print '\nnumber of arguments:'
                                          print len(sys.argv)
                                          
                                          print '\nhere are the given arguments:'
                                          for arg in sys.argv:
                                              print arg
                                          
                                          print '\nhere is the third argument:'
                                          print sys.argv[3]
                                          
                                          
                                          [PROMPT] $ ./args.py one two three
                                          
                                          number of arguments:
                                          4
                                          
                                          here is the given arguments:
                                          ./args.py
                                          one
                                          two
                                          three
                                          
                                          here is the third argument:
                                          three
                                          
                                          [PROMPT] $ ./args.py catch errors
                                          
                                          number of arguments:
                                          3
                                          
                                          here is the given arguments:
                                          ./args.py
                                          catch
                                          errors
                                          
                                          here is the third argument:
                                          Traceback (most recent call last):
                                            File "./args.py", line 13, in <module>
                                              print sys.argv[3]
                                          IndexError: list index out of range
                                          
                                          • Useful topics
                                          • joystick-selection tool
                                          • rpie-art tool
                                          • achievements I made
                                          cyperghostC 1 Reply Last reply Reply Quote 1
                                          • cyperghostC
                                            cyperghost @meleu
                                            last edited by

                                            @meleu That's it
                                            Thank you

                                            D 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

                                            Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.