|
if somebody press Esc he go to another function |
a b
Member #8,092
December 2006
|
Is some instruction in c++ or library allegro that if somebody press Esc in function1() or in function2() then he go to important() - because I am doing this now as the example:
|
Steve Terry
Member #1,989
March 2002
|
Did you compile with -f-important-esc-function in the compiler flags? ___________________________________ |
LennyLen
Member #5,313
December 2004
|
Firstly, you don't need to use readkey() to access the key[] array. And why can't you just use: if (key[KEY_ESC]) important(); edit: Steve: Meanie.
|
a b
Member #8,092
December 2006
|
I must use readkey() - without that my program wrong run, and I wrote bad example - It should be:
If somebody press "Esc" - then function1() should will finish and should will go to the start point - important() |
LennyLen
Member #5,313
December 2004
|
Quote: I must use readkey() - without that my program wrong run If you need to use readkey() without checking what it returns, then your program probably isn't written properly. The code you have posted makes very little sense, so it's hard to tell exactly what you're trying to achieve. But what you probably need in function1() is: if (key[KEY_ESC]) { esc_was_pressed = 1; return; } And then in main(): if (esc_was_pressed) important(); Another alternative is just having the following in function1(): if (key[KEY_ESC]) { important(); return; } Without knowing more about the program flow or what you're trying to achieve, I don't know which would be better.
|
Albin Engström
Member #8,110
December 2006
|
Albin found: "code of horrors" |
a b
Member #8,092
December 2006
|
if (key[KEY_ESC]) { important(); return; } after that program go to meni and exit - I think this is fault "return" in above code :/ |
LennyLen
Member #5,313
December 2004
|
Then post some REAL code that actually makes sense!!! And please start using function names that describes what the function does. I have absolutely no idea what the hell it is you are trying to do, which makes it near-impossible to help you.
|
a b
Member #8,092
December 2006
|
I can't give you all my code I give you a little part of my code - I had to change names to english because first they were in polish because I am Pole and I deleted 99% my code so maybe something is wrong :
|
LennyLen
Member #5,313
December 2004
|
If I was going to implement a menu, I'd first define an enumeration to declare the states the program can be in. eg: enum { MENU, GAME, INSTRUCTIONS, AUTHORS, EXIT }; Then I'd add a loop that checks the state. eg:
Then, in your menu function, I'd change the state depending on what the user selects. eg:
|
a b
Member #8,092
December 2006
|
not, I want that when somebody press ESC then he go to menu (first player choose option from menu for example "new game", and then he can play, but when he then press ESC he go to menu) and you only change fragment of my code which doing that same thing |
LennyLen
Member #5,313
December 2004
|
I'm not going to write your program for you! That was just an EXAMPLE of another way of doing something that I EXPECTED YOU to be able to modify to your needs. On that note: I quit. You're on your own.
|
a b
Member #8,092
December 2006
|
And I don't want that you write code for me, my code was only example so you can't write for me. You idea is wrong. |
Evert
Member #794
November 2000
|
You should not mix input from the key[] array and readkey(), they serve different purposes. |
a b
Member #8,092
December 2006
|
Evert
Member #794
November 2000
|
Quote: this not compile Count your closing parentheses... Quote: this [...] is better and shorter
It is shorter (but the readkey() version can be written more elegantly) and actually worse, depending on the situation. |
a b
Member #8,092
December 2006
|
I must use readkey() and key[] because ONLY then program good run. Without readkey at present showed option in menu when I press "->" it jumps over about several of position to lower part and it should about 1 position. And when I have readkey() without key[] - when I pressing another keys than "->" and "<-" postions change and I can't go to game when I am on 1. position in menu and press ENTER (1. position in my menu is "new game"). And when I use readkey() and key[] - EVERYTHING IS PERFECT:
|
Evert
Member #794
November 2000
|
Did you even bother to read (and try to understand) what I wrote? Quote: I must use readkey() and key[] because ONLY then program good run. You're doing something wrong then. Post a sample of the code that doesn't run properly. |
a b
Member #8,092
December 2006
|
ok Ever so what is wrong - could you take attachment - then you will see that if I delete readkey() program runs wrong - you can press only KEY_UP, KEY_DOWN or ENTER.
|
Evert
Member #794
November 2000
|
Quote: ok Ever Evertt Quote: - could you take attachment No, I can't. I can't open rar archives from this machine. Make sure that if you do use readkey() instead of key[] you call it only once. |
a b
Member #8,092
December 2006
|
ok - now it is "zip" file As I say without "readkey()" - everything is wrong. |
Richard Phipps
Member #1,632
November 2001
|
a b: You are just going to have to trust us when we say is it wrong. Listen to the advice you get instead of trying to fight it. |
a b
Member #8,092
December 2006
|
I want trust you but when I delete readkey() - everything is wrong |
tobing
Member #5,213
November 2004
|
I had some trouble with key[] and readkey also with my first project. The point is, you have to use allegro's functions for key input the way they are designed, which is a little different from what you do. Other people here can explain this very much better than I can, but look into do_dialog() and similar functions to make your UI. It has its root somewhere in the parallel existence of a keyboard buffer, which is handled by routines like readkey(), and the key[] array, which allows immediate access to the current key states. For my needs, I'll do my next game with guichan, which is an excellent GUI library, but still in heavy development (working its way to version 0.6). |
a b
Member #8,092
December 2006
|
I understand but why must I use readkey() and key[] in below code (also in attachment) ? Do somebdoy know ? If I use only readkey() or only key[] program runs wrong:
|
|
|