Is there a way to interact with the command line from in-game? I would like to have the user be able to jump on a console or even just interact with a button and have the game run a Python script in the background, ideally passing the output back to the user in-game.
-
1\$\begingroup\$ You might run into serious problems with focus - as far as I know only one application(window) can have the focus at a time. My bet is to create imposter for the things you need (create something that looks like command line but only can do a few needed things, there cant be that many to actually need a command line). \$\endgroup\$wondra– wondra2014-09-06 00:02:34 +00:00Commented Sep 6, 2014 at 0:02
2 Answers
You can run your Python script using a spawn or fork-exec command and have the two programs running simultaneously, it will be invisible to the user. Or you can use a simpler exec command which will pause your main program while running the Python script. The exact name, implementation and functionality of both these options depend on the programming language and operating system.
But in general, if you need scripts in a game it is probably a better option to use an embedded script engine. Lua is a very popular option. Alternately both Unreal Engine and Unity come with a scripting engine, if they are already embedded in your application anyway you could probably use one of those.
You can have the game generate a text file with instructions from an in-game command line for the external python script to run.