Python- How to skip whats been printed when returning? -
so, trying skip printed lines , come raw_input. need loop?
class stuff(scene): def enter(self): print "this text" print "this text" print "this text" print "this text" print "this text" action = raw_input("> ") if action == "blah" print "this text" return 'stuff' when this, repeats of printed lines, how go raw_input?
you create attribute class keeps track of whether you've printed text before. when do print text, set attribute appropriately. example:
class stuff(scene): def __init__(self): self.seen_description = false #other initialization goes here def enter(self): print "end of road" if not self.seen_description: print "you standing beside small brick building @ end of road north." print "a river flows south." print "to north open country, , around dense forest." self.seen_description = true action = raw_input("> ") if action == "go inside": print "you enter brick building" return 'brick building' x = stuff() x.enter() x.enter() result:
end of road standing beside small brick building @ end of road north. river flows south. north open country, , around dense forest. > wait end of road > wait here, extended description first time call enter, , skipped on subsequent calls.
Comments
Post a Comment