I have a problem in the game engine:
I made a game, but I needed a highscore program for the points.
So I wrote an external program in C + +, that is to be executed later as exe by a button in my blender game.
I tried it with the commands: os.startfile var; open and run () in the text window and a sensor, controllers (with the python script), but nothing happens and the background window is displayed: Command / entry could not be found or is misspelled …
But everything is correct …
I would be really happy if someone could tell me how a blender game can open a different program (in the same folder).
The subprocess module’swhat you need for that task, should be fairly straight foward.
Thank you for your help,
but unfortunately it still does not work.
I am a noob in programing with python and do not understand English so well also in the Python manual …
I do not know where the problem is, maybe the problem is in the Logic window:
- sensor (keyboard with enter key) with controller (with a Python script) connected
- in the text window the script:
- import os
var = “Highscore.exe”
- p1.stdout.read print (“Highscore.exe”)
- path = logic.expandPath (“Highscore.exe”)
Maybe I made a mistake or the program can not be executed or opened .
I need help…
many thanks! now it works!
but after that I had to specify the full path of the file
and my memory operations were also stored in the folder from blender…
Can you set the option somewhere to put files in the folder from the .blend file?
Happy to help!
As far as I’m aware you’d have to move the files manually over to the .blend’s current folder. You could probably write something with python that can do it, have a look at the shutil module, I’ve never used it myself, I only know it exists, so I can’t give you any examples.
So you could use shutil to move the files over and then use subprocess to open them in the .blend directory. If that’s the route you want to go then if you get really stuck I might have a proper look at shutil’s API at the weekend and see what I can come up with.
But, honestly, I think it’s better to either specify the full file path or just move them manually to where you want them. Particularly if you plan to share this .blend with others who might not have the same directory structure as you (which would cause all kinds of trouble :(). Furthermore, there are users, like myself, that wont run someone else’s code that messes with files/directories/exec/eval/etc as it’s all too easy for a sloppy line to cause harm (unless, of course, you FULLY understand what the code is doing).