Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » if somebody press Esc he go to another function

This thread is locked; no one can reply to it. rss feed Print
if somebody press Esc he go to another function
Jonatan Hedborg
Member #4,886
July 2004
avatar

In your first example, the program would halt at "val = readkey();", until a key is pressed. The other one would not. Not the same.

Richard Phipps
Member #1,632
November 2001
avatar

Michael Faerber
Member #4,800
July 2004
avatar

Man, I think I've never seen so many crazy people on a thread before! :o

--
"The basic of informatics is Microsoft Office." - An informatics teacher in our school
"Do you know Linux?" "Linux? Isn't that something for visually impaired people?"

LennyLen
Member #5,313
December 2004
avatar

Quote:

Man, I think I've never seen so many crazy people on a thread before!

Hey! I mean, who... that is... oh, never mind.

a b
Member #8,092
December 2006

1. so should I change readkey() to keypressed() ?
2. Somebody told that I shouldn't to call out in function function . I read that is good idea ..... so I don't know - should I change that more call function should be in main() ??

3. This:

readkey();
if(key[KEY_0])

should be:

int k = readkey()>>8;
 k = readkey()>>8;
if(k==KEY_0)

???????? yes ??????????
If I understand: http://www.allegro.cc/manual/api/keyboard-routines/readkey thanks ">>8" I can use "key+key" yes ??

Evert
Member #794
November 2000
avatar

Quote:

1. so should I change readkey() to keypressed() ?

No!
Read the manual on what each of these functions do.

Quote:

3. This:
[...]
should be:

Yes. Sortof. You should only call readkey() once, not twice at that point. Read the keypressed() manual entry.

Quote:

thanks ">>8" I can use "key+key" yes ??

I don't understand what you mean.

LennyLen
Member #5,313
December 2004
avatar

You didn't answer question 2, Evert. :-*

Jonatan Hedborg
Member #4,886
July 2004
avatar

Quote:

Somebody told that I shouldn't to call out in function function . I read that is good idea ..... so I don't know - should I change that more call function should be in main() ??

I don't even know what that means.

I'm actually starting to think that a b is, in fact, THE MOST SOPHISTICATED TROLL EVER!

Kauhiz
Member #4,798
July 2004

Yeah, like I said, we're getting Punk'd and this guy is having a blast :-/

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

a b
Member #8,092
December 2006

1.Kaukiz told:
"You can't just call function after function"
Do you agree ??

2. I read manual but it is in english so I don't understand everything - if I want that program stop untill somebody press any key then I must use keypressed() yes ?

3.
int k = readkey()>>8;
k = readkey()>>8;
if(k==KEY_0)

thanks ">>8" I can use for example "ctr+shift" (keyboard shortcuts) yes ??

PS. Jonatan Hedborg I don't like Sweden :D

Evert
Member #794
November 2000
avatar

Quote:

if I want that program stop untill somebody press any key then I must use keypressed() yes ?

No.
readkey() will read a key from the buffer and wait if there is no key in the buffer. keypressed() will tell you if there is a key in the buffer. So
val=readkey();
blocks, while

val=0;
if (keypressed()) val=readkey();

does not.

Quote:

thanks ">>8" I can use for example "ctr+shift" (keyboard shortcuts) yes ??

No!

TFM said:

if ((val & 0xff) == 3) /* ctrl+letter */
allegro_message("You pressed Control+C\n");

if (val == (KEY_X << 8)) /* alt+letter */
allegro_message("You pressed Alt+X\n");

EDIT: For shortcuts, check out the key_shifts variable as well.

Kauhiz
Member #4,798
July 2004

Quote:

1.Kaukiz told:
"You can't just call function after function"
Do you agree ??

I assume you mean what I said, and you just simply CAN NOT SPELL! You apparently missed the next part of that statement, which is the more important one. You can call functions after each other, of course. You shouldn't just call the menu function when someone presses a key. There's a HUGE difference there.

Quote:

2. I read manual but it is in english so I don't understand everything - if I want that program stop untill somebody press any key then I must use keypressed() yes ?

Nope, the exact opposite. If you can't understand a part of the manual, copy the part here and ask.

Quote:

int k = readkey()>>8;
k = readkey()>>8;
if(k==KEY_0)

That's wrong, you should only call readkey() once. If you knew basic C++, you'd understand why.

Quote:

PS. Jonatan Hedborg I don't like Germany :D

WTF?

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

a b
Member #8,092
December 2006

readkey()>>8

I know bite shift in only theoretical side, I never use it. Bite shift faster some actions. And here what is faster ? Read key is faster ?

Jonatan Hedborg
Member #4,886
July 2004
avatar

Quote:

PS. Jonatan Hedborg I don't like Sweden :D

that was random, even for you.

For the record: I don't like you.

Kauhiz
Member #4,798
July 2004

Quote:

Bite shift faster some actions. And here what is faster ? Read key is faster ?

What the HELL!!? Read the goddamn manual!? It doesn't make anything faster, it gets the goddamn scancode for you! Please, please, please tell me you're only joking here!

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

Richard Phipps
Member #1,632
November 2001
avatar

It's now 140 posts (with this one) to try to resolve this question.. :)

a b
Member #8,092
December 2006

but why in "k = readkey()>>8;" is "8" ?? why bite shift in right is "8" ??

Evert
Member #794
November 2000
avatar

Instead of us answering that, you should try to answer the following questions:

How many bits are there in one byte (on a PC)?
What happens if you have a double-byte word and shift all bits in it from the upper byte to the lower byte?
What does that imply if you use a double byte word to store two one-byte values, one inthe upper and one in the lower byte?

Richard Phipps
Member #1,632
November 2001
avatar

Because >> 8 is one byte and readkey() returns a word (2 bytes):

Quote:

int readkey();
Returns the next character from the keyboard buffer, in ASCII format. If the buffer is empty, it waits until a key is pressed. You can see if there are queued keypresses with keypressed().

The low byte of the return value contains the ASCII code of the key, and the high byte the scancode.

I.e. xxxxxxxx | xxxxxxxx (8 bits | 8 bits)
Scancode | Asci value

Jonatan Hedborg
Member #4,886
July 2004
avatar

Do you even try to improve your English? People say "bit", you still use "bite". Kauhiz nickname is visible most of the time - is your H-key broke? My god...
Let's just stop this thread right here. Please? I'm working up a brain aneurysm...

piccolo
Member #3,163
January 2003
avatar

[off topic]
I am not going to flame to prove my point.
[/off topic]

from what i understood the problem was that the game went back to the menu when esc was pressed in the started game,and you want it to end the game.
the mods that i made will fix that problem.

when esc was pressed before the mods to the code, a break was issued. This break ends the current loop. when the current loop is ended you are put back to the spot in your code where you entered that loop. That spot is the menu loop.
so what i did to fix this is change that break to the end-game call you made.

wow
-------------------------------
i am who you are not am i

Kauhiz
Member #4,798
July 2004

But you're still discarding the return value of readkey() which is wrong.

Quote:

Let's just stop this thread right here.

We're probably making a record here. Almost 150 posts already to solve a trivial problem (which has already been solved many times over)! I think it'll be fun to see how long this thread will go :)

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

piccolo
Member #3,163
January 2003
avatar

i just wanted to get the main problem fixed. He has been informed that there are some other design errors in his code. After reviewing his code, i saw that those errors do not harm the game in a drastic way. So these errors can be corrected in a later design faze.(now that he knows of them)

wow
-------------------------------
i am who you are not am i

Kauhiz
Member #4,798
July 2004

Quote:

(now that he knows of them)

We could have a whole nother debate on this point...

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

a b
Member #8,092
December 2006

thanks piccolo for your help :)

I also will change in code to:
int k=readkey()>>8;
.............
;]

But:
word = 2 bytes ? Thanks I didn't know that.
but if readkey() returns 2 bytes so why readkey()>> can't be "16" ? 2 bytes = 16



Go to: