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

    Running a script on ROM start....

    Scheduled Pinned Locked Moved Help and Support
    runcommandmarquee
    3 Posts 2 Posters 778 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.
    • G
      Goofy12
      last edited by

      I have a big panel of LEDs I want to show some animations on as a marquee once a game is started. Im familiar with the runcommand-onstart.sh file and have got it working as below.

      All the LED animation work I do is done using python so Ive got the runcommand-onstart-sh to run python script and pass the details of the ROM being run into the python file:
      The runcommand-onstart.sh looks like this:

      #!/bin/bash
      # put this in /opt/retropie/configs/all/.
      /usr/bin/python3 /home/pi/pyarg.py $1 $2 $3
      

      And the python file looks like this:

      #!/usr/bin/python
      
      import sys
      
      #$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.
      
      #[0] seems to be just this python progrmme name
      retrosys = sys.argv[1]
      emul = sys.argv[2]
      romfile = sys.argv[2]
          
      with open('start.txt', 'a') as out:
          out.write(retrosys + "," + emul + "," + romfile + '\n')
      
      #now do things
      #print("doing")
      #time.sleep(10)
      #print("done")
      #time.sleep(5)
      

      It all works fine and I saved the ROMs to a text file just to check.]

      This is great as allows me to know which ROM is running and then use the python script to show an appropriate animation on the LED display.

      At the bottom of the python script, I want to loop an animation which would cause the runcommand-onstart.sh to run indefinitely and get stuck. I know this as I tried it with the 'sleep' command in python it just stops while this is completed

      I know its a bit of a convoluted way of doing things but I really want to run the animations in python! Im not great on bash scripting and just wondered if there is a way to start the python script from the runcommand-onstart.sh and then carry on with loading the game?

      1 Reply Last reply Reply Quote 0
      • mituM
        mitu Global Moderator
        last edited by

        Run the script in the background from the onstart script:

        /usr/bin/python3 /home/pi/pyarg.py $1 $2 $3 &
        

        or

        nohup /usr/bin/python3 /home/pi/pyarg.py $1 $2 $3
        

        You should also take care of stopping the script when the emulator exits, from the runcommand onend script.

        G 1 Reply Last reply Reply Quote 0
        • G
          Goofy12 @mitu
          last edited by

          @mitu Thats great, it worked, just added an & at the end. Thanks very much!

          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.