(curses) issue about inch()

J

Jimmy

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
 
S

Steve Holden

Jimmy said:
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
 
J

Jimmy

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 :(
 
S

Steve Holden

Jimmy said:
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:

What you really need is a logical and with 255:

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
 
J

Jimmy

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:


What you really need is a logical and with 255:


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

thanks, it works!
python is cool, however, the python community is even cooler :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top