in-game console

TimErwin

04-08-2007 18:22:48

Hi!

How would you implement an in-game console? Would you call exec with what the user typed? How do I get the console output? I guess it should be pretty easy, but I just don't get the key idea...

Thanks,
Tim

Kanma

04-08-2007 18:50:57

To get the console output, create a class with a write() method:

class MyOutput:
def write(self, text):
do something with text here...


and set sys.stdout (and sys.stderr):

import sys

sys.stdout = MyOutput()
sys.stderr = MyOutput()



I use the following class to redirect the outputs to one of my objects and also to the standard ones (or at least, the previously set ones):

class StreamMux:
def __init__(self, stream1, stream2):
self.stream1 = stream1
self.stream2 = stream2

def write(self, text):
self.stream1.write(text)
self.stream2.write(text)

...

sys.stdout = StreamMux(sys.stdout, scriptingManager.outStream)
sys.stderr = StreamMux(sys.stderr, scriptingManager.errStream)

TimErwin

04-08-2007 19:21:11

Wow, that's cool. Thanks, Kanma. I especially like your muxing.

And how do I make my app execute user strings?

Regards,
Tim-Erwin