0

I was wondering if it is possible to write the pygame code to a separate terminal so that you can still do things like print to the terminal. When pygame's display becomes initialized it seems to be impossible to put any input into the terminal. Any way to get around this?

I also want to know that if this is possible can one the other terminal edit the one running pygame to change certain things?

Github

  • 1
    Can you be more specific about the issue? I print things to the terminal all the time while debugging a pygame game. You can even take input from the terminal, but it will pause the game loop until you finish the input. – ecline6 Apr 24 '13 at 04:42
  • When i try to make the terminal take input while pygame is running it just does not let me. It just seems like its just frozen. – Justin Darveau Apr 24 '13 at 04:52
  • It will be frozen until you enter something and press enter. Your script is waiting for your input. If that's not what's going on, you'll need to add the related code so we can see what's going on. You should be able to do exactly what your asking without doing anything fancy. – ecline6 Apr 24 '13 at 04:54
  • My problem might be being caused that i'm not actually sure that i'm asking for input again after i start it. That still shouldn't matter though should it? – Justin Darveau Apr 24 '13 at 04:57
  • No it does not work. This program basically starts out only with the terminal. If you type in a certain command then pygame is started. After its started i can't seem to enter any more input into the terminal. Hope this gives better insight. – Justin Darveau Apr 24 '13 at 05:01
  • There is probably a bit to much code to put on here. The pygame is really a branch off of the main part of the program. I'd show you but there is just a lot of code – Justin Darveau Apr 24 '13 at 05:09
  • If you can find a way to pare it down to just the bits required to understand, then do it. You could always include a link to the full source if needed. Or find a way to describe the problem and implementation fully without the code. Beyond that, I can't help. Sorry. – ecline6 Apr 24 '13 at 05:12
  • Im putting it on github right now – Justin Darveau Apr 24 '13 at 05:17

1 Answers1

0

Ok, once you initialize pygame and start your pygame loop in startDisplay() in Commands.py, you are essentially leaving your main() loop in game.py. So your repeated request for input won't happen again. If you want to call for input during the loop in startDisplay() you'll need to do it expressly there. As I stated above, this will pause your game until you enter a command, which obviously isn't very good. You could build a little logic around it and only request input during a break in the action or implement a Pause event (using a key event) which would subsequently call the prompt for a command.

ecline6
  • 896
  • 8
  • 15
  • Do you know of a way that i can do this though. My efforts don't seem to be working – Justin Darveau Apr 24 '13 at 15:10
  • Since the the while loop in main() seems to just a be a loop to continue prompting, get rid of the loop and just make it a function that prompts for a command. That way you can call the function on a Pause key event in the startDisplay() loop. Does that make sense? One possible option for running both loops continuously could be multithreading or multiprocessing, but I'm not experienced with them so I can't offer any suggestions for implementing. – ecline6 Apr 24 '13 at 16:12
  • I guess it makes some sense but this would require to remake most of the program would it not? – Justin Darveau Apr 24 '13 at 17:14
  • The pause key with the prompt function would take all of 15 minutes to do. The multithread/processing shouldn't require a full rewrite. You would just encapsulate the game loop and the prompt loop into two different threads. The game loop needs data from the prompt loop, but if I understand your code, you don't need to go the other way too, so I wouldn't think there would be much of a syncing issue. I can't put a time on how long to add the threading, but my naive assumption is that it shouldn't take a lot of code to do it. – ecline6 Apr 24 '13 at 17:23