Jimmy wrote: > On Sep 17, 12:07 am, Steve Holden <[EMAIL PROTECTED]> wrote: >> Jimmy wrote: >>> hi, all >>> I attempt to use the function inch() to get the character at the >>> current position, and compare it with a particular character like : >>> if screen.inch(x,y) == 'F' >>> but this method doesn't seem work, can anyone tell me the reason and >>> how to corrent it >>> thanks >> The reason is because something is wrong, and yo fix it by correcting >> that issue. >> >> In other words, if you could be a bit more specific about *how* it >> doesn't work (like, show us the code you are running,a nd any error >> messages or evidence of incorrect results) you will be able to get some >> help that actually helps you. >> >> Would you go to a car repair shop with faulty brakes and just tell them >> "my car isn't working"? >> >> regards >> Steve >> -- >> Steve Holden +1 571 484 6266 +1 800 494 3119 >> Holden Web LLC/Ltd http://www.holdenweb.com >> Skype: holdenweb http://del.icio.us/steve.holden >> >> Sorry, the dog ate my .sigline > > thanks, > actually i'm writing a game like mine,the pertainign code is: > > def mark(): > """mark the bomb""" > (row, col) = gb.scrn.getyx() > x = gb.scrn.inch(row,col) > if x == 'F': > gb.scrn.addch(row,col, 'X',curses.color_pair(3)) > else: > gb.scrn.addch(row,col, 'F',curses.color_pair(3)) > > gb.scrn.move(row,col) > gb.scrn.refresh() > > the situation is x never equals 'F', even when it really is! > I checked the mannual and found the return value of inch() consists > the actual character(low 8bits) > and the attributes, so I tried the following: (x<<24)>>24,cause I > guess the int is 32bits long. > but it still doesn't work :( > Well first of all, thanks for reading the manual.
Let's suppose the value you are receiving is 1234 (clearly more than 8 bits). Unfortunately for you, recent versions of Python don't just use 32-bit integers, but extend the values into Python's long values where necessary. See: >>> (1234<<24)>>24 1234L >>> What you really need is a logical and with 255: >>> 1234 & 255 210 >>> Hope this helps. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Sorry, the dog ate my .sigline -- http://mail.python.org/mailman/listinfo/python-list