RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    Scripting help for replacing retroarch.cfg

    Scheduled Pinned Locked Moved Help and Support
    copyconfig filescriptingautomatedoverlays
    49 Posts 4 Posters 8.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.
    • cyperghostC
      cyperghost
      last edited by cyperghost

      https://ghostbin.com/paste/t7ws7

      Here is a working script!
      As I said --- it's was pseudocode with some errors
      2x done without do, break condition was set wrong, dialogboxes showed unneeded options....

      If you run this script you will see just 3do standard for ex. as output.. Therefore
      You must exchange the commands in line 49-52 with your copy commands.

      So you stripped down from 30kB to 3kB and can faster navigate ;)

      Greetings fly out to @meleu (<--- this guy is responsible for my rising interest in bash) and @TMNTturtlguy (<--- this guy is responsible that I get in need to use bash ... EUREKA!)

      TMNTturtlguyT meleuM 2 Replies Last reply Reply Quote 2
      • F
        FlashPC
        last edited by FlashPC

        @cyperghost Thanks, its so tidy

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

          @flashpc Does it work for you?
          Can you post the full script with all alterings please?

          You can even alter the titles and backtitles of each menu for ex. like this --backtitle " Your selected console is ${1^^} " So you have an overview of your systemchoice if you want to exchange the shader. Just a convenient addon...

          ... There is a small bug Please add a return between line 53 & 54. I update code.

          What is the difference between overlay and overlay-real?

          F 1 Reply Last reply Reply Quote 0
          • TMNTturtlguyT
            TMNTturtlguy @cyperghost
            last edited by

            @cyperghost said in Scripting help for replacing retroarch.cfg:

            Greetings fly out to @meleu (<--- this guy is responsible for my rising interest in bash) and @TMNTturtlguy (<--- this guy is responsible that I get in need to use bash ... EUREKA!)

            Greetings back to you @cyperghost! Hope all is well. I just come up with crazy ideas, and pretty down and dirty ways to try to make them work, you and @meleu are the true artists that clean up the messes I start!

            meleuM 1 Reply Last reply Reply Quote 1
            • cyperghostC
              cyperghost
              last edited by

              @TMNTturtlguy Yes I'm fine. Thank you - it's always a pleasure to do some coding stuff

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

                Nice job guys!

                @cyperghost I would like to recommend this reading when you have a time: Importance of code indentation. ;-)

                • Useful topics
                • joystick-selection tool
                • rpie-art tool
                • achievements I made
                1 Reply Last reply Reply Quote 1
                • F
                  FlashPC @cyperghost
                  last edited by FlashPC

                  @cyperghost said in Scripting help for replacing retroarch.cfg:

                  ... There is a small bug Please add a return between line 53 & 54. I update code.

                  I found that out, does the additional return clear the $shaderchoice variable? I just added "shaderchoice=" at the start of the modemenu routine and that allowed me to select another mode after returning the main screen

                  @cyperghost said in Scripting help for replacing retroarch.cfg:

                  What is the difference between overlay and overlay-real?

                  overlay has side art and a bezel around the screen, overlay-real is the same with an additional semi transparent layer over the play area to mimic sun glare and smears on an old CRT TV

                  The current script is here

                  Thanks again

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

                    @tmntturtlguy said in Scripting help for replacing retroarch.cfg:

                    you and @meleu are the true artists that clean up the messes I start!

                    haha! I tried to be an artist. I even created a blog with some drawings I made: https://meleuartblog.wordpress.com/

                    Stopped updating that 2 years ago...

                    @FlashPC sorry for this off-topic post on your thread. :)

                    • 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 cyperghost

                      @meleu Hehe... I like artists ;)
                      Drawing is good for relaxing and maybe once a time you come back to design studies. Believe me I've married a talented artist - my wife do great drawings if there is muse. You can do also good scratches with Corel Painter and a small Bamboo Tableu.

                      Btw.: This one is epic ;)

                      @FlashPC

                      I found that out, does the additional return clear the $shaderchoice variable? I just added "shaderchoice=" at the start of the modemenu routine and that allowed me to select another mode after returning the main screen

                      Yes that also helps, maybe it helps to declare shaderchoice as local variable.
                      You did a great job ;) Even if the coding is a bit "uncommon" ;) You use tons of if-then clauses to set a variable. Please don't see this as an offence but now you have to maintain two locations of systemnames. It's better to use an array for this and to create the menu out of this, too. But as the script works for you it's okay ....

                      1 Reply Last reply Reply Quote 1
                      • F
                        FlashPC
                        last edited by

                        @cyperghost Thanks man, I'm an absolute noob when it comes to this type of coding, I know it's uncommon, but following the information and instructions from various sources I'm finding its a little bit disjointed and I've done some BASIC self training back in the 90s and recently Lua for creating (very simple) programs in windows.

                        I know of if / then clauses and so it meant I could a load a variable with text depending on the selection. But I want to take this further as a pet project and a learning exercise.

                        This is how I started with Lua (indigorose auto media studio), I started with a basic idea and then added to it, tidying the code, adding features, and streamlining by searching forums and checking YouTube.

                        Any learning directions would be definitely be appreciated, I will never be a master but if I could muddle through it would be great

                        Cheers guys
                        Paul

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

                          @flashpc Yes the coding style looks like BASIC... btw - you can install FreeBasic on the Pie and create binaries out of this. So if you want to share your programms the other users don't need an interpreter. So you can stick to any language you want... bash or BASIC.

                          But I did not know about whiptails --notags command. So your systemlist looks really tidy ;) If you don't like whiptail you can stick to dialog. Dialog is a more expanded box creater as whiptail with much more commands but I prefer whiptail because of it's simply usage.

                          F 1 Reply Last reply Reply Quote 0
                          • F
                            FlashPC @cyperghost
                            last edited by

                            @cyperghost said in Scripting help for replacing retroarch.cfg:

                            But I did not know about whiptails --notags command. So your systemlist looks really tidy ;)

                            Thanks dude, I found it because I was looking for a way to remove the OK button and read the info for the whiptail command and thought --notags would be interesting.

                            1 Reply Last reply Reply Quote 0
                            • F
                              FlashPC
                              last edited by

                              @cyperghost Hey mate, can you please have a look at this as and see if I am on the right track, I am having a go at arrays to tidy the code.

                              Click here

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

                                @FlashPC
                                I think it can be done much easier without in need for a settings variable.

                                I write some pseudo-code okay

                                
                                # Your array
                                console=("3do" "Panasonic" "nes" "Nintendo Entertainment system"......)
                                
                                # Now let whiptail work for you... as it expects two strings for creating text boxes, we give them...
                                
                                # I try to use proper indentation for better code reading
                                # We start our loop for systemchoice here
                                while true
                                    do
                                        syschoice=$(whiptail -- back title " Systemmenu ...... \ 
                                            --nocancel --menu " Choose " \
                                            "<--" "... back to EmulationStation"
                                            "${console[@]}" \          # <--- This creates the full menu structure out of array!!
                                            .... )
                                
                                            case "$syschoice" in
                                                "<--") break ;;
                                                *) shaderchoice $syschoice ;; # <--- Call to function as in v3 script
                                            esac
                                    done
                                

                                Later you can get real systemname out of array with ${console[$1]} (I hope so) ;)

                                EDIT:

                                Add this to function modemenu

                                local idx=0
                                until [[ "${console[idx]}" == "$1" ][
                                    do
                                       idx=$(( $idx + 1 ))
                                    done
                                

                                Then use whiptail and higher idx+1 and you've the console name... That's it and it was funny ;)

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

                                  @FlashPC

                                  Here is the full working script... Change as you like

                                  #!/bin/bash
                                  
                                  # Retroswap.sh
                                  #############
                                  # This script lets you switch retroarch config files.
                                  # v4 09.09.2017 by cyperghost and FlashPC
                                  #
                                  # Place this script in /home/pi/RetroPie/retropiemenu/
                                  # In order to run the script you must create the following folders:
                                  #    1. /opt/retropie/configs/all/retroswap
                                  #    2. within that folder create a folder for each system
                                  #       2.1 create there folder "overlay"
                                  #       2.2 create there folder "overlay-real"
                                  #       2.3 create there folder "shader"
                                  #       2.4 create there folder "standard"
                                  #
                                  # full example path for 3DO = /opt/retropie/configs/all/retroswap/3do/overlay
                                  #
                                  # Within each folder you have created place a retroarch.cfg file.
                                  # The file needs to be named the same in each folder.
                                  # Place your current retroarch_shader.cfg in the shader folder. 
                                  # Name the file retroarch.cfg.
                                  #
                                  # Greetings fly out to meleu and TMNTturtleguy
                                  #
                                  # Please respect the work of others
                                  
                                  # -- F U N C T I O N S --
                                  modemenu ()
                                  {
                                  
                                  local idx=0
                                  local shaderchoice
                                  until [[ "${console[idx]}" == "$1" ]]
                                      do
                                         idx=$(( $idx + 1 ))
                                      done
                                  
                                  
                                  until [[ "$shaderchoice" == "<--" ]]
                                      do
                                          shaderchoice=$(whiptail --backtitle " Console is ${console[idx+1]} " \
                                          --title " Choose " \
                                          --nocancel --menu "Choose an option" 0 0 0 \
                                              "<--" "... back to systemselection" \
                                              "overlay" "Use Basic Overlay & Scanlines" \
                                              "overlay-real" "Use Realistic Overlay & Scanlines" \
                                              "shaders" "Use Shaders...." \
                                              "standard" "Disable Overlays & Scanlines" \
                                              2>&1 > /dev/tty)
                                  
                                  
                                      case "$shaderchoice" in
                                          overlay) echo "$1 Overlay" && sleep 2 ;;
                                          overlay-real) echo "$1 RealOverlay" && sleep 2 ;;
                                          shaders) echo "$1 shaders" && sleep 2 ;;
                                          standard) echo "$1 standard" && sleep 2 ;;
                                      esac
                                  done
                                  }
                                  
                                  #-- A R R A Y --
                                  # Feel free to add and edit new console
                                  # TAKE CARE OF UPPER AND LOWER CASE!
                                  
                                  console=("3do" "Panasonic 3DO" "atari2600" "Atari 2600" "atari5200" "Atari 5200" "atarijaguar" "Atari Jaguar" "coleco" "ColecoVision" \
                                           "dreamcast" "Sega Dreamcast" "famicom" "Nintendo Famicom" "intellivision" "IntelliVision" "markiii" "Sega Mark III" \
                                           "mastersystem" "Sega Master System" "megadrive" "Sega MegaDrive" "segacd" "Sega MegaCD" "n64" "Nintendo 64" \
                                           "neogeo" "SNK Neo-Geo AES" "nes" "Nintendo Entertainment System" "nintendobsx" "Nintendo Satelliview" \
                                           "pcengine" "NEC PC-Engine" "pcenginecd" "NEC PC_EnigneCD" "psx" "Sony Playstation" "saturn" "Sega Saturn" \
                                           "sega32x" "Sega 32X" "sfc" "Nintendo Super Famicom" "snes" "Super Nintendo Entertainment System" "tg16" "TurboGrafx 16" \
                                           "tg16cd" "TurboGrafx 16CD")
                                  
                                  # -- M A I N - L O O P --
                                  
                                  while true
                                      do
                                          syschoice=$(whiptail --backtitle " Choose " --title " Choose " \
                                          --nocancel --menu "Select Console" 0 0 0 \
                                              "<--" "... back to ES" \
                                              "${console[@]}" \
                                              "<--" "... back to ES" \
                                              2>&1 > /dev/tty)
                                  
                                      case "$syschoice" in
                                          "<--") break ;;
                                          *) modemenu "$syschoice" ;;
                                      esac
                                  done
                                  

                                  @meleu ;) How about the indentations?

                                  F 1 Reply Last reply Reply Quote 0
                                  • F
                                    FlashPC @cyperghost
                                    last edited by

                                    @cyperghost Hey mate, I really appreciate your help, I am away from my Pi for a while so I cannot simply load the code, and for me to learn can I just confirm a few things.

                                    @cyperghost said in Scripting help for replacing retroarch.cfg:

                                    modemenu ()
                                    {
                                    
                                    local idx=0
                                    local shaderchoice
                                    until [[ "${console[idx]}" == "$1" ]]
                                        do
                                           idx=$(( $idx + 1 ))
                                        done
                                    
                                    until [[ "$shaderchoice" == "<--" ]]
                                    do
                                          shaderchoice=$(whiptail --backtitle " Console is ${console[idx+1]} " \
                                          --title " Choose " \
                                          --nocancel --menu "Choose an option" 0 0 0 \
                                              "<--" "... back to systemselection" \
                                              "overlay" "Use Basic Overlay & Scanlines" \
                                              "overlay-real" "Use Realistic Overlay & Scanlines" \
                                              "shaders" "Use Shaders...." \
                                              "standard" "Disable Overlays & Scanlines" \
                                              2>&1 > /dev/tty)
                                    done
                                    }
                                    

                                    In this function am I right in guessing that the 2 'locals' at the start, clears the shaderchoice variable and sets idx to zero, then program will loop the console array searching for $1, using idx as a counter, then once it has found the result it locks down idx to a number, which when the menu runs it uses the next result within the array to display the menu title.

                                    console=("3do" "Panasonic 3DO" "atari2600" "Atari 2600" "atari5200" "Atari 5200" "atarijaguar" "Atari Jaguar" "coleco" "ColecoVision" \
                                         "dreamcast" "Sega Dreamcast" "famicom" "Nintendo Famicom" "intellivision" "IntelliVision" "markiii" "Sega Mark III" \
                                         "mastersystem" "Sega Master System" "megadrive" "Sega MegaDrive" "segacd" "Sega MegaCD" "n64" "Nintendo 64" \
                                         "neogeo" "SNK Neo-Geo AES" "nes" "Nintendo Entertainment System" "nintendobsx" "Nintendo Satelliview" \
                                         "pcengine" "NEC PC-Engine" "pcenginecd" "NEC PC_EnigneCD" "psx" "Sony Playstation" "saturn" "Sega Saturn" \
                                         "sega32x" "Sega 32X" "sfc" "Nintendo Super Famicom" "snes" "Super Nintendo Entertainment System" "tg16" "TurboGrafx 16" \
                                         "tg16cd" "TurboGrafx 16CD")
                                    

                                    In the array are the backslashes used to continue the array onto another line without breaking the array

                                    while true
                                    do
                                        syschoice=$(whiptail --backtitle " Choose " --title " Choose " \
                                        --nocancel --menu "Select Console" 0 0 0 \
                                            "<--" "... back to ES" \
                                            "${console[@]}" \
                                            "<--" "... back to ES" \
                                            2>&1 > /dev/tty)
                                    
                                    case "$syschoice" in
                                        "<--") break ;;
                                        *) modemenu "$syschoice" ;;
                                    esac
                                    done
                                    

                                    Will the "${console[@]}" part actually populate both the tags and the descriptions within the whiptail menu?

                                    2>&1 > /dev/tty)
                                    

                                    And finally what does the above terminal code mean?

                                    cyperghostC F 2 Replies Last reply Reply Quote 0
                                    • cyperghostC
                                      cyperghost @FlashPC
                                      last edited by cyperghost

                                      @cyperghost Hey mate, I really appreciate your help, I am away from my Pi for a while so I cannot simply load the code, and for me to learn can I just confirm a few things.

                                      Okay - but I'm not a professional

                                      @cyperghost said in Scripting help for replacing retroarch.cfg:

                                      modemenu ()
                                      {
                                      
                                      local idx=0
                                      local shaderchoice
                                      until [[ "${console[idx]}" == "$1" ]]
                                          do
                                             idx=$(( $idx + 1 ))
                                          done
                                      
                                      until [[ "$shaderchoice" == "<--" ]]
                                      do
                                            shaderchoice=$(whiptail --backtitle " Console is ${console[idx+1]} " \
                                            --title " Choose " \
                                            --nocancel --menu "Choose an option" 0 0 0 \
                                                "<--" "... back to systemselection" \
                                                "overlay" "Use Basic Overlay & Scanlines" \
                                                "overlay-real" "Use Realistic Overlay & Scanlines" \
                                                "shaders" "Use Shaders...." \
                                                "standard" "Disable Overlays & Scanlines" \
                                                2>&1 > /dev/tty)
                                      done
                                      }
                                      

                                      In this function am I right in guessing that the 2 'locals' at the start, clears the shaderchoice variable and sets idx to zero, then program will loop the console array searching for $1, using idx as a counter, then once it has found the result it locks down idx to a number, which when the menu runs it uses the next result within the array to display the menu title.

                                      Yes... locale variables are fire and forget ones. They are working only inside the function and if the funtion is finished the variables values are nomore available (or set to zero) a bit uncommon imho but it's a neat thing.

                                      Yes the first loop compares array with called $syschoice and sets an counter (idx). If condtion is true (loop until) the whiptail menu will be entered. There you just set idx+1 and ask array and you'll get the "User System Description".

                                      console=("3do" "Panasonic 3DO" "atari2600" "Atari 2600" "atari5200" "Atari 5200" "atarijaguar" "Atari Jaguar" "coleco" "ColecoVision" \
                                           "dreamcast" "Sega Dreamcast" "famicom" "Nintendo Famicom" "intellivision" "IntelliVision" "markiii" "Sega Mark III" \
                                           "mastersystem" "Sega Master System" "megadrive" "Sega MegaDrive" "segacd" "Sega MegaCD" "n64" "Nintendo 64" \
                                           "neogeo" "SNK Neo-Geo AES" "nes" "Nintendo Entertainment System" "nintendobsx" "Nintendo Satelliview" \
                                           "pcengine" "NEC PC-Engine" "pcenginecd" "NEC PC_EnigneCD" "psx" "Sony Playstation" "saturn" "Sega Saturn" \
                                           "sega32x" "Sega 32X" "sfc" "Nintendo Super Famicom" "snes" "Super Nintendo Entertainment System" "tg16" "TurboGrafx 16" \
                                           "tg16cd" "TurboGrafx 16CD")
                                      

                                      In the array are the backslashes used to continue the array onto another line without breaking the array

                                      That is cosmetic for a better reading and maintaining. The backslash is used as breakline, a newline will work like ; and will introduce/end a command

                                      while true
                                      do
                                          syschoice=$(whiptail --backtitle " Choose " --title " Choose " \
                                          --nocancel --menu "Select Console" 0 0 0 \
                                              "<--" "... back to ES" \
                                              "${console[@]}" \
                                              "<--" "... back to ES" \
                                              2>&1 > /dev/tty)
                                      
                                      case "$syschoice" in
                                          "<--") break ;;
                                          *) modemenu "$syschoice" ;;
                                      esac
                                      done
                                      

                                      Will the "${console[@]}" part actually populate both the tags and the descriptions within the whiptail menu?

                                      Yes, as I wrote above whiptail in menu mode ask for two tags for an entry, so we feed whiptail with that values. I think it's also possible to use two arrays (as it was your first intention) but think about maintaining the code. You have always to use the correct counter position for "systemname" (3do) and "User Systemname" (3DO Philips Emulator thing.......). As humans are not perfect and may make mistakes it's a variant I won't prefer..... Therefore I coded this script for you.

                                      2>&1 > /dev/tty)
                                      

                                      And finally what does the above terminal code mean?

                                      Unix uses different channels for inputs, standard output and error outputs.
                                      0 is standard input (keyboard for ex.)
                                      1 is standard ouput (PC monitor for ex. = terminal)
                                      2 is standard error ouput (PC monitor for ex. =terminal)

                                      So we redirect error messages (channel 2) to 1 tty is standard terminal
                                      if you write /dev/null then every message error and normal progress will be send to nirvana.

                                      I repeat I'm in no means a professional coder and there may be errors.

                                      For the idx-do-loop... I think there is an easier approch to do this.
                                      As bash seems to be a very logic language you must ask if the whiptail command extracts the full array and you can select an entry the index number must be somewhere handeled during the whiptail call ;)

                                      1 Reply Last reply Reply Quote 0
                                      • F
                                        FlashPC
                                        last edited by

                                        @cyperghost @meleu @TMNTturtlguy Thank you so much guys, I'm pretty sure the script is now done. I am proud to say I added a little to the project but it was down to you guys.

                                        I have learnt a lot in the last week, and I realise that there is no single way to do anything, and I hope that once I get into this a bit more I can help others with my dirty code...lol

                                        meleuM 1 Reply Last reply Reply Quote 3
                                        • meleuM
                                          meleu @FlashPC
                                          last edited by

                                          @flashpc Glad to know you achieved what you want. :-)

                                          Feel free to ask shell scripting questions in this thread: https://retropie.org.uk/forum/topic/11900/shell-scripting-topic/

                                          • Useful topics
                                          • joystick-selection tool
                                          • rpie-art tool
                                          • achievements I made
                                          1 Reply Last reply Reply Quote 0
                                          • F
                                            FlashPC @FlashPC
                                            last edited by FlashPC

                                            Hey guys, I've been tinkering and adding more features, and for about 2 weeks I've been fighting trying to get the interface working with controllers, instead of the keyboard. I had some success with Joymap which worked great with the PS3 controller, which is what I have been using initially, so I thought 'Sweet, that was easy....' and it was until I tried a PS2/PSX twin USB adaptor.

                                            Joymap would correctly map Player 2 but not Player 1, next I tried xboxdrv which nicely maps all the buttons and axis for Player 1 so the menu worked again, but when I plugged in an Xbox controller it would kill the controller on exit, so that was out too.

                                            I was at my wits end and kind of put it on the back burner, and wandered through the internet looking for inspiration on a way to try and fix this, but it ended up me watching YouTube for a few days...

                                            Finally I came back to the forum and found @meleu RetroPie joystick selector, which claimed to change the joystick order within Retropie. I started the install script and my controllers worked.... so I had a look at his script and couldn't work it out, but I did notice it was running from the folder,

                                            home/pi/RetroPie-Setup/scriptmodules/supplementary/ 
                                            

                                            I was able to run the script from Emulation Station, but not from the terminal.

                                            So I had a look at other Attract Mode Setup scripts which run from within the retropiemenu folder.

                                            For Example Configure Wifi.sh

                                            #!/usr/bin/env bash
                                            sudo /home/pi/RetroPie-Setup/retropie_packages.sh retropiemenu launch/home/pi/RetroPie/retropiemenu/wifi.rp
                                            

                                            So I had a go at linking retroswap.sh in the retropiemenu folder
                                            And after using this script

                                            printf "\033[H\033[2J"
                                            sudo /home/pi/RetroPie-Setup/retropie_packages.sh retropiemenu launch /home/pi/RetroPie/retropiemenu/retroswap.sh
                                            printf "\033[H\033[2J"
                                            

                                            Every controller works straight away, no workarounds, no crashes, no screwed up Attract Mode on return.

                                            so for the TL:DR version
                                            If you create a script which you want to control with a controller instead of the keyboard, create a linked file within the retropiemenu folder and run the simple script like the one above to execute your script, and all the heavy lifting for the controller interface will be done for you.

                                            meleuM 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.