Andy911 Posted October 11 Share Posted October 11 (edited) I feel like this must have been discussed in the past, but I've been searching and cannot find an answer. Before a MAME Rom is launched, I want to run a python script. I need to pass the filename for the selected rom to the script. I cant figure out how to get Launchbox to pass the filename. I've created a Python script, and put it in a batch file. Using Additional Apps feature, I launch the batch file which successfully runs the py script. I've tried using variationsof %romlocation% in the cmd line parameters. It literally passes "%romlocation%" to the batch file, but does not substitute the filename as expected. I'd appreciate any help. Thanks. Edited October 11 by Andy911 Quote Link to comment Share on other sites More sharing options...
sundogak Posted October 11 Share Posted October 11 (edited) 1 hour ago, Andy911 said: I feel like this must have been discussed in the past, but I've been searching and cannot find an answer. Before a MAME Rom is launched, I want to run a python script. I need to pass the filename for the selected rom to the script. I cant figure out how to get Launchbox to pass the filename. I've created a Python script, and put it in a batch file. Using Additional Apps feature, I launch the batch file which successfully runs the py script. I've tried using variationsof %romlocation% in the cmd line parameters. It literally passes "%romlocation%" to the batch file, but does not substitute the filename as expected. I'd appreciate any help. Thanks. These are the variables that I am aware of (no good place documenting so just picked up via change logs, etc): %romfilename% - Filename of the ROM WITHOUT extension %romextension% - Extension of the ROM file (ie, .rom) %romlocation_noquotes% - Path to the ROM without quotes %noromfile% - Replaced with empty string, suppresses rom file being added to end of the command line %romfile% - Rom name with extension Have you tried %romfilename% or %romfile% as this should work for what you are trying to do. Edited October 11 by sundogak edit error Quote Link to comment Share on other sites More sharing options...
Andy911 Posted October 11 Author Share Posted October 11 I tried the ones you listed. No luck. Launchbox doesn't substitute as expected. Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted October 11 Share Posted October 11 37 minutes ago, Andy911 said: I tried the ones you listed. No luck. Launchbox doesn't substitute as expected. Parameters cannot be passed to Additional Apps or Running Scripts. The quick and dirty, yet effective way to do what you need is to create a new emulator. This 'emulator' can be anything you can execute, like a batch file, AutoHotkey script, Python script etc. LaunchBox will pass the parameters (mentioned above) to the 'emulator'. From there, have it do whatever pre-launch things need to be done and then have it launch MAME with its required parameters. You can also have your 'emulator' wait until MAME exits and run something else before exiting itself [if needed]. If you don't need to run anything after MAME exits, you may still want to have your 'emulator' wait for it (MAME) to exit before closing the script so that the LaunchBox 'closing' screen will show ("Thank you for Playing"). Quote Link to comment Share on other sites More sharing options...
Andy911 Posted October 11 Author Share Posted October 11 (edited) Wrapping my head around this one. I set up an "emulator", which actually runs my batch file with the python script. LB adds the full path to the rom as a parameter, even though I left the default command-line parameters blank. I tried using the other parameters, but LB still is not substituting the info. I need the filename, so my py script can look up info in an xml file. Although I can probably make this work by having my py script parse the filename from the full path, I feel like I'm missing something here. Shouldn't LB be substituting the info when %romfile% is in the command line parameters? Edited October 11 by Andy911 Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted October 11 Share Posted October 11 1 hour ago, Andy911 said: Shouldn't LB be substituting the info when %romfile% is in the command line parameters? It does. Having %romfile% be the only thing in the command-line parameters is the same as leaving it blank. Quote if %romfile% is not in the custom command-line parameters, it will be added at the end. Otherwise it's placed in the order you put it. With the command-line parameters blank, you capture that [%romfile%] in the batch file as %1. What's all included in %romfile% depends on the check boxes you have checked [in the emulator]. Say the MAME game is "1942". Per the above set checkboxes, that's what %1 will be. "1942" (without quotes). To run this game from a batch file which is the 'emulator', the batch file would look like: (again, using the above check boxes) set game=%1 cd "D:\LaunchBox\Emulators\MAME\" "D:\LaunchBox\Emulators\MAME\mame.exe" %game% And to confuse matters more... you can put %romfilename% as the only parameter, and %1 will be "1942" (without quotes) regardless of the checkboxes. Note: %romfile% will still be added to the end of the parameters that are passed to the 'emulator' and can be captured in the batch file as %2. Quote Link to comment Share on other sites More sharing options...
Andy911 Posted October 11 Author Share Posted October 11 Ok. The checkboxes are working for me. And to confuse matters more... you can put %romfilename% as the only parameter, and %1 will be "1942" (without quotes) regardless of the checkboxes. Note: %romfile% will still be added to the end of the parameters that are passed to the 'emulator' and can be captured in the batch file as %2. However, I tried %romfilename% as the only parameter. I tried capturing both parameters %1 and %2. It still does not substitute the date for %romfilename%. Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted October 11 Share Posted October 11 22 minutes ago, Andy911 said: However, I tried %romfilename% as the only parameter. I tried capturing both parameters %1 and %2. It still does not substitute the date for %romfilename%. Not really sure what "date" you're referring to. Edit the 'emulator' you created that points to the batch file. Share a screenshot of the Details section so we can see what you have. Quote Link to comment Share on other sites More sharing options...
Andy911 Posted October 12 Author Share Posted October 12 Data (not date). Batch File: @echo off REM Pass the first and second arguments (ROM filename and other parameter) to the Python script python "G:\My Drive\Projects\Projects\Arduino RasPi and Robotics\Python to Arduino Led Control\Test LB to PY pass filename.py" %1 %2 pause Py Script import sys def main(): # Capture the two parameters if len(sys.argv) > 1: rom_filename = sys.argv[1] second_param = sys.argv[2] print(f"ROM filename: {rom_filename}") print(f"Second parameter: {second_param}") else: print("No filename passed.") if __name__ == "__main__": main() input("Press Enter to close...") Output: Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted October 12 Share Posted October 12 @Andy911 Looks like you're running a version of LaunchBox prior to 13.15. (%romfilename% became available in 13.15.) Otherwise, you would see RomFile in the sample command. But for your purposes, you don't need that parameter. Remove it and have the batch file just pass %1. Quote Link to comment Share on other sites More sharing options...
Andy911 Posted October 12 Author Share Posted October 12 Ok. Thanks for your help. I'll probably update anyway. In the latest updates, is there a way to pass the rom metadata (date of release, controls, etc...) upon launch? I have an xml file that I can parse from, but it sure would be simpler if I could get LB to just send it to my custom scripts. Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted October 12 Share Posted October 12 12 minutes ago, Andy911 said: In the latest updates, is there a way to pass the rom metadata (date of release, controls, etc...) upon launch? I have an xml file that I can parse from, but it sure would be simpler if I could get LB to just send it to my custom scripts. No. The only parameters that can be passed are the ones @sundogak mentioned and a couple more found here: Quote Link to comment Share on other sites More sharing options...
Andy911 Posted October 12 Author Share Posted October 12 (edited) Thank you! Edited October 12 by Andy911 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.