Emulation game-start scripts folder
-
I have been plugging away at this a while now and cant seem to get anywhere . I am trying to run a script as a game starts, and i found that emulationstation will run scripts at certain events (one of those events being game-start). I created a .sh file named printparms.sh and i gave it full permission when typing ls -la i get:
-rwxrwxrwx 1 root root 17 Jun 26 17:46 printparms.shI've tried these 2 different VERY simple scripts and neither works when launching a game. It does work if it call it in shell:
##First file try:
FILE="/opt/retropie/configs/all/emulationstation/mylog.txt"
echo "WORKING??" >> $FILE##second file try:
echo "WORKING??"in both scenarios when look at the es_log.txt i get this message:
Jun 26 17:59:53 lvl2: Attempting to launch game...
Jun 26 17:59:54 lvl1: /home/pi/.emulationstation/scripts/game-start/printparms.sh is not executable. Did you 'chmod u+x'?. Skipping this script.
Jun 26 17:59:54 lvl2: /opt/retropie/supplementary/runcommand/runcommand.sh 0 SYS n64 /home/pi/RetroPie/roms/n64/Legend\ of\ Zelda,\ The\ -\ Ocarina\ of\ Time\ (USA)\ (Rev\ B).n64
Jun 26 18:00:19 lvl2: Creating window...
Jun 26 18:00:20 lvl2: Created window successfully.I have gone to the file and typed (which it is already marked as x):
sudo chmod u+x printparms.shI still get the same message. Any help would be great!
-
@Kaydron Your script is incorrect, it doesn't have the shebang which allows the shell to determine how to execute the script. Don't use
root
for regular operations, yourpi
user has enough rights to add/edit the files needed.
Here's a simple script working:pi@retropie:~/.emulationstation/scripts/game-start $ pwd /home/pi/.emulationstation/scripts/game-start pi@retropie:~/.emulationstation/scripts/game-start $ cat 1_echo.sh #!/usr/bin/env bash echo "Working" pi@rertropie:~/.emulationstation/scripts/game-start $ ls -l 1_echo.sh -rwxr-xr-x 1 pi pi 35 Jun 27 03:45 1_echo.sh
Launching a game executes the script
[..] Jun 27 03:45:45 lvl3: fireEvent: game-start /home/pi/RetroPie/roms/ngpc/Metal\ Slug\ -\ 2nd\ Mission\ \(World\)\ \(En,Ja\).zip Metal Slug - 2nd Mission (World) (En,Ja) Jun 27 03:45:45 lvl3: executing: /home/pi/.emulationstation/scripts/game-start/1_echo.sh "/home/pi/RetroPie/roms/ngpc/Metal\ Slug\ -\ 2nd\ Mission\ \(World\)\ \(En,Ja\).zip" "Metal Slug - 2nd Mission (World) (En,Ja)" [..]
-
Thank you so much! IT WORKED!
I've been learning stuff in the past month or 2 and i faintly remember the she bang but stuff worked without it. I read into it a bit more and i see why it is needed.
On top of trying to get the event to fire i tried pushing info out to a text file and had several difficulties there (quotes need some places and not in others). I'm not use to the syntax for shell files yet.
I will be reading into shell scripting a bit more to hopefully eliminate questions here relating to shell scripts. If anyone has a couple sites that would be good reference paste them here.
Here is a full working script i put together for anyone browsing at a later time that wants to see some basic shell:
SCRIPT DETAILS
Script file contents:
#!/usr/bin/env bash FILE="/opt/retropie/configs/all/emulationstation/mylog.txt" echo before echo HELLO WORLD >> "$FILE" echo "$*" >> "$FILE" echo after
Script file output:
shell screen/window shows:
before after
File also shows:
HELLO WORLD /home/pi/RetroPie/roms/n64/Legend\ of\ Zelda,\ The\ -\ Ocarina\ of\ Time\ \(USA\)\ \(Rev\ B\).n64 Legend of Zelda, The - Ocarina of Time (USA) (Rev B)
Pieces discussed below:
#!/usr/bin/env bash
-Shebang (as they call it) specifies what interrupter (program) to execute the script.
FILE="/opt/retropie/configs/all/emulationstation/mylog.txt"
saves the string "/opt/retropie/configs/all/emulationstation/mylog.txt" to the variable FILE
echo before [...] echo after
These 2 lines use the command
echo
that will print before on one line of the shell window/screen and after on another line of the shell window/screen.echo HELLO WORLD >> "$FILE"
This line prints the words HELLO WORLD using echo again but the syntax
>>
forces output to go to the file specified by the variable FILE ... BE SURE TO INCLUDE BOTH $ and " quotes (FILE="/opt/retropie/configs/all/emulationstation/mylog.txt"
).
I'm unsure why but when running it in shell by.\printparms.sh
quotes are NOT needed around $FILE, but ARE needed when triggered by the game-start event.echo "$*" >> "$FILE"
Finally last line introduces a new item
$*
when a script runs when arguments/parameters are sent to it. These parameters can be accessed by specific syntax $ usually denotes arguments are being accessed. In this example$*
was used to show all variables passed as one long string. This is why we got line/home/pi/RetroPie/roms/n64/Legend\ of\ Zelda,\ The\ -\ Ocarina\ of\ Time\ \(USA\)\ \(Rev\ B\).n64 Legend of Zelda, The - Ocarina of Time (USA) (Rev B)
in the file.See https://www.baeldung.com/linux/use-command-line-arguments-in-bash-script for more indepth information about arguments. This link does not specify the use of
$*
but has lots of other good information. -
@Kaydron said in Emulation game-start scripts folder:
I will be reading into shell scripting a bit more to hopefully eliminate questions here relating to shell scripts. If anyone has a couple sites that would be good reference paste them here.
The canonical reference is https://tldp.org/LDP/abs/html/, highly recommended for anyone starting or learning Bash scripting.
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.