Homepage › Forums › RetroPie Project › Everything else related to the RetroPie Project › Running script when launching rom
- This topic has 6 replies, 2 voices, and was last updated 9 years, 5 months ago by sselph.
-
AuthorPosts
-
02/22/2015 at 10:38 #88580jamiem777Participant
Hi, I am trying to run a script to find the latest played game when launching a rom, so when launching at the rom boot it should read it as the currently playing rom. I am using the gamelist.xml to achieve this and then output it to a 16×2 lcd display. This is all working the only problem I am having is getting the script to run when launching a rom. Can anyone point me to where I would need to look to launch this script when launching a rom. Thanks in advance
Jamie02/22/2015 at 14:01 #88588sselphParticipantThe Emulators are started with the command listed in /etc/emulationstation/es_systems.cfg
You’ll see each system listed with a command that is invoked.
<system> <fullname>Nintendo Entertainment System</fullname> <name>nes</name> <path>~/RetroPie/roms/nes</path> <extension>.nes .NES .zip .ZIP</extension> <command>/opt/retropie/supplementary/runcommand/runcommand.sh 4 "/opt/retropie/emulators/retroarch/bin/retroarch -L /opt/retropie/libretrocores/neslibretro/fceumm_libretro.so --config /opt/retropie/configs/all/retroarch.cfg --appendconfig /opt/retropie/configs/nes/retroarch.cfg %ROM%" "neslibretro"</command> <platform>nes</platform> <theme>nes</theme> </system>
So you might be able to modify this script to invoke your script. /opt/retropie/supplementary/runcommand/runcommand.sh
02/22/2015 at 14:15 #88592sselphParticipantIf this approach works a simplification could be to pass $command in the bash script to your script. Since the command typically has the rom path as the last argument you should be able to parse it to extract the currently playing game. Might be easier than trying to figure out which gamelist was updated last. This would be before the eval $command which actually starts the emulation. Then after that you can add a call to the script to update the screen to remove the currently playing game since you have exited.
02/22/2015 at 16:01 #88601jamiem777ParticipantThanks Sselph, The first post has helped me I was able to run the script and it worked perfectly apart from the gamelist.xml doesnt appear to get updated until after exiting emulation station so it really makes that method of searching rather redundant now. I am now trying to incorporate the details from your second post how would I go about passing the $command into my script. I should be able to work out how to fix it up so that I can get the right details out of it just I haven’t got an idea where to start with this. Here’s my code so far.
from AndyPi_LCD import AndyPi_LCD import lxml.etree as ET root = ET.parse("./RetroPie/roms/ports/gamelist.xml") lsp = root.findall(".//lastplayed") mylist = [t.text for t in lsp] newest = max(mylist) gname = root.xpath("./game[lastplayed/text()='{}']/name/text()".format(newest)) print(gname) namelcd = "".join(gname) print(namelcd) lcd=AndyPi_LCD() lcd.lcd_init() lcd.led(512) lcd.static_text(1,"c","Latest Game:") lcd.static_text(2,"c",namelcd)
02/22/2015 at 19:22 #88620sselphParticipantIn the bash script you’d do:
your_script.py set $command eval $command your_script.py clear
You might have to do
your_script.py set "$command"
Then in your python script you do something like this. sys.argv[1] has the action and sys.argv[2] has the full command in it. So you’d need to try and extract the rom file name off the end but since it could contain spaces the split is tricky. Then you could optionally look up the pretty name from the gamelist. There might be a better way to do the xml look up and there are bound to be typos or errors but you get the idea.
import sys from os import path from AndyPi_LCD import AndyPi_LCD import lxml.etree as ET # Clear the screen if sys.argv[1] == "clear": lcd=AndyPi_LCD() lcd.lcd_init() lcd.led(512) lcd.static_text(1,"c","RetroPie v.2.6.0") lcd.static_text(2,"c","") return 0 # Assume the command was set. command = sys.argv[2] file_path = command.replace('\ ', '___').split()[-1].replace('___', ' ') dir, file_name = path.split(file_path) root = ET.parse('%s/gamelist.xml' % dir) namelcd = file_name for game in root.iter('game'): if game.find('path').text == './%s' % file_name: namelcd = game.find('name').text break lcd=AndyPi_LCD() lcd.lcd_init() lcd.led(512) lcd.static_text(1,"c","Playing:") lcd.static_text(2,"c",namelcd)
02/22/2015 at 21:42 #88637jamiem777ParticipantThat’s great thanks Sselph. I will try this out and let you know how I get on.
06/29/2015 at 05:14 #100954sselphParticipantHi,
Never heard back so don’t know if you got this working but I needed a similar ability so I created a library to monitor the running emulator and rom. I went ahead and create a standalone binary for this use case. If you need to try it you can see how to use it at:
Script to Monitor Running Emulator and ROM for other scripts
It is alpha state right now.
-
AuthorPosts
- The forum ‘Everything else related to the RetroPie Project’ is closed to new topics and replies.