![]() |
|
if somebody press Esc he go to another function |
Evert
Member #794
November 2000
![]() |
Quote: nooooooo - your idea with readkey()>>8 is bad
No, your implementation is. I'm not going to spoon-feed you, but I will give you one more hint (even if Richard already gave the exact same advice above): don't declare it as a global variable; you want to keep calling readkey, don't you? Aside, I realise this is probably a reflection of your English not being very good, but I will tell you this: I have been programming for more than fifteen years, and programming in C with Allegro for nine years. I do not take kindly to a novice user getting angry and calling code examples I give "bad" because he fails to implement it properly. I seriously suggest that you invest some time on that attitude. Quote: I readed but it isn't simply when I can't good english........ Feel free to ask any question related to the manual. Feel free todirectly ask the friendly Polish regulars for advice is Polish if you need to. |
a b
Member #8,092
December 2006
|
1. This is a bit uncomfortable declaring in every function this - do you judge ? 2. And when I want that programme will stop as long as I will press ANY(WHATEVER) key then I use only: "readkey()" yes ?? 2. I change: on that: okay ?? |
Richard Phipps
Member #1,632
November 2001
![]() |
Quote: 2. I change: readkey(); on that: int k = readkey()>>8; Please think about what we have said, and what you have read in the manual. That will answer your question.. Ask some polish people here if the english is too difficult. |
Evert
Member #794
November 2000
![]() |
Another hint: you only need to make a very small change to the readkey() call in your original code. |
X-G
Member #856
December 2000
![]() |
Quote: Oh how right he was.
-- |
Kauhiz
Member #4,798
July 2004
|
Quote: 1. This is a bit uncomfortable declaring in every function this - do you judge ? I'm not quite sure what you're question is, but technically if you wanted k to be a global variable, you could declare int k; globally and the do k = readkey()>>8; when you need to (albeit I don't see any point in making it into a global variable, and using k as a name for a global variable is a horrible idea). --- |
a b
Member #8,092
December 2006
|
Evert: "you only need to make a very small change to the readkey() call in your original code." - what do you mean ?? |
Evert
Member #794
November 2000
![]() |
I'm not going to explain more than that. I cannot say more without writing down the actual code, and I want you to do that yourself. |
a b
Member #8,092
December 2006
|
Evert
Member #794
November 2000
![]() |
I'm completely lost now. EDIT: even if your English is not very good, you can explain a bit better what you mean. |
LennyLen
Member #5,313
December 2004
![]() |
Quote: If the code you have now works, what is your question? He's asking you if he changed the right part.
|
Evert
Member #794
November 2000
![]() |
I don't know. Last I knew, he wanted to do something like the pseudo-code I posted here. |
LennyLen
Member #5,313
December 2004
![]() |
Quote: Why he would need a while loop at all is beyond me, because I don't think I understand what he's asking for. It's simple. He has a menu. He wants the UP and DOWN keys to change the current selection, and ENTER to accept it. [I'm assuming] ESC exits the menu.
|
a b
Member #8,092
December 2006
|
yes, yes LennyLen But now I must give question - is it possible because I don't know: Now I have 6 functions, during the game (not in menu but in game) player will press keys many times - and I must write every time when player should press key if this key isn't ESC because if it is ESC then game should exit. Is it possible write as a global that if player press ESC game exit and I can't check it in each place when player should press some key for example: "enter" or "->" or another ?? |
LennyLen
Member #5,313
December 2004
![]() |
Quote: Is it possible write as a global that if player press ESC game exit and I can't check it in each place when player should press some key for example: "enter" or "->" or another ?? Richard Phipps already answered that question.
|
Kauhiz
Member #4,798
July 2004
|
Do it like this: bool gameRunning = true; ... int main() { //Initialization stuff goes here while(gameRunning) { //Main part of your game if(k == KEY_ESC) gameRunning = false; } //De-init stuff goes here return 0; } That is if you want the game to exit when ESC is pressed. --- |
a b
Member #8,092
December 2006
|
Kauhiz I made that but when I press ESC - nothing do:
|
Kauhiz
Member #4,798
July 2004
|
Did you even look at the code you wrote!? Obviously it's not going to quit, because you have while(go!=0) in your meni() function, and go isn't set to anything inside that loop This is basic stuff that has nothing to do with allegro! If you expect to get any help on this forum in the future you have to at least TRY to solve your problems yourself, because otherwise people will get frustrated and just give up! Just like Evert said, you don't need a while-loop there! Do you just hit some random keys on your keyboard and then compile to see if it works? --- |
a b
Member #8,092
December 2006
|
I try made what you said and I change my code ...... Firstly it was:
This loop is infinite on purpose. It must be infinite (only when somebody is in index 3 and press enter will be exit and now I want also make that if somebody press ESC program will be exit ) so just therefore I ask is it possible that if somebody press ESC program will exit. This program is also example because I have bigger program and more functions, for example I have function (I will must change there readkey() and key[]): Just therefore I ask if it possible that that ESC was pressed then the end of programme |
Kauhiz
Member #4,798
July 2004
|
Quote: This loop is infinite on purpose. It must be infinite No, wrong! You DO NOT want to have an infinite loop in your code! Secondly, if you can make the program exit when ENTER is pressed, why can't you make it exit when ESC is pressed? There's absolutely no difference!! And BTW, returning when ENTER is pressed isn't even the best way to do that. Replace this:if((k==KEY_ENTER)&&index==3){return 0;} with this:if((k == KEY_ENTER) && index == 3) || k == KEY_ESC) go = 0; --- |
X-G
Member #856
December 2000
![]() |
Wow, you guys really are a bunch of incurable masochists, aren't you? -- |
Kauhiz
Member #4,798
July 2004
|
I know, it's bad --- |
Richard Phipps
Member #1,632
November 2001
![]() |
It's soo true! |
a b
Member #8,092
December 2006
|
no, no, no - this code is only example, in my real code in main after function "meni()" is another function and if I do as you say function after "meni()" in main will be run - and I don't want this. |
Richard Phipps
Member #1,632
November 2001
![]() |
|
|