Computer Science Canada Ignoring input? |
Author: | RsX [ Sat Apr 01, 2006 7:21 pm ] |
Post subject: | Ignoring input? |
I made a pong game for school. I have a problem that when the game ends, you naturally end up with your finger still on the key. The program stores the input and then it gets used when the program goes back to the main menu, causing chaos ![]() Is there any command I can use to get the program to ignore keyboard inputs between certain points? |
Author: | do_pete [ Sat Apr 01, 2006 7:29 pm ] |
Post subject: | |
You could stick a delay in to let the user take his fingers of the buttons |
Author: | TokenHerbz [ Sat Apr 01, 2006 7:29 pm ] |
Post subject: | |
Are you using keydown? or getch.. Try adding a "Input.Pause" or perhaps a delay for a second... |
Author: | Tony [ Sat Apr 01, 2006 7:33 pm ] | ||
Post subject: | |||
if you're using getch, you could flash the buffer by reading all of it.
|
Author: | do_pete [ Sat Apr 01, 2006 7:34 pm ] |
Post subject: | |
Input.Pause wouldn't work because it would only pause until the user presses something |
Author: | RsX [ Sat Apr 01, 2006 7:43 pm ] |
Post subject: | |
The thing is, I tried delaying, but even that doesnt pause the input. I tried adding a delay of 2 seconds after the game is over, but then the user still has his finger on s for like 20 miliseconds. |
Author: | RsX [ Sat Apr 01, 2006 7:45 pm ] | ||
Post subject: | |||
this is the users code:
Theres an option to either play 2 players or 1 against the computer, hence the if multi [/code] |
Author: | [Gandalf] [ Sat Apr 01, 2006 7:52 pm ] |
Post subject: | |
Tony has already posted the answer, it should be good enough for you to create some working code. If you have a more specific question, ask it, but try to solve the problem on your own first. |
Author: | TokenHerbz [ Sat Apr 01, 2006 7:56 pm ] | ||
Post subject: | |||
you should have a nice code, what i mean is like...
and i don't get the resons you posted that bit... |
Author: | RsX [ Sat Apr 01, 2006 8:17 pm ] | ||
Post subject: | |||
I updated it to what you suggested but it still doesnt work:
Ill tell you how it works... The whole program, including the getch, is within a loop... Once the game is over, you exit the loop and enter the loop that was wrapping the games loop. Then it asks if you want to play again, so automatically you dont even see that message because your finger was still pressing the key as you exited the loop. Plus, you would most likely enter a sub-menu which forces you to retype all the settings. |
Author: | RsX [ Sat Apr 01, 2006 8:19 pm ] |
Post subject: | |
Thats why I need an input pauser, to pause inputting in the parent loop (the one wrapping the games loop). P.S. isnt there a way to edit posts lol |
Author: | Tony [ Sat Apr 01, 2006 8:24 pm ] | ||
Post subject: | |||
no, you don't get a way to edit your posts ![]() your program should be like:
you flash the buffer right before the menu |
Author: | RsX [ Sat Apr 01, 2006 8:39 pm ] |
Post subject: | |
Great! That helped ![]() If I can ask one more question regarding the code above... How would I make it move smother? Using the keys W and S the 2nd player is supposed to move his pong up and down, but it doesnt move smoothly at all... Once the user presses he has to wait about 1 second before seeing a movement, and it cuts off a lot. Is there any way to fix that? |
Author: | RsX [ Sat Apr 01, 2006 8:40 pm ] | ||
Post subject: | |||
This is the code that needs re-writing (sorry about the double posting)
|
Author: | do_pete [ Sat Apr 01, 2006 8:51 pm ] |
Post subject: | |
Look up how to use View.Update to get rid of the flicker and use reals instead of ints for your coordinates and speed variables, this will allow you to shorten your delays |
Author: | RsX [ Sat Apr 01, 2006 8:54 pm ] |
Post subject: | |
Im using turing version 4.0.0 View.Update doesnt seem to work with it ![]() |
Author: | do_pete [ Sat Apr 01, 2006 9:25 pm ] |
Post subject: | |
Are you putting setscreen ("offscreenonly")/View.Set ("offscreenonly") at the beginning of your code? |
Author: | RsX [ Sat Apr 01, 2006 9:31 pm ] | ||
Post subject: | |||
View.Set gives an error... Anything that looks like
doesnt work |
Author: | Tony [ Sat Apr 01, 2006 10:17 pm ] |
Post subject: | |
View.Update is Turing 4.0.5's feature. RsX - the only way to reduce flashes is to draw as least as you can, as fast as you can. So take out any delays that you might have, and try to think of a way where you have to draw the least to go from frame A to frame B. (so for example don't redraw the entire background if you don't have to. |
Author: | RsX [ Sat Apr 01, 2006 10:33 pm ] |
Post subject: | |
I dont really mind the flashes. Its the way the pong is controled. When you press and hold W to make the pong move up, you have to wait like 3 seconds and then it wont even move smoothly, its choppy and moves whenever it wants. My questions is how to set it so that it moves smoother and as soon as you click? I know that it doesnt have to do with the delay because player 1 is controlled by the movement of the mouse and it moves extremely smooth and not-choppy at all. |
Author: | Cervantes [ Sat Apr 01, 2006 10:37 pm ] |
Post subject: | |
Tony wrote: View.Update is Turing 4.0.5's feature.
View.Update was Turing v4.x.x, wasn't it? View.UpdateArea was 4.0.5. RsX: If you're using 4.0.0, I would think View.Update should work. Is it producing an error, saying that it's unrecognized? Or does it just not help with the flickering? |
Author: | cool dude [ Sat Apr 01, 2006 10:40 pm ] |
Post subject: | |
to make it go faster as others said u can lessen your delays. but i had sort of the same problem a long time ago too. basically if u go to your control pannel select classic view and then click on keyboard. u can actually select the sensitivity, thus if u make it fast then when u press on the keys in the game it will go a lot faster. ![]() |
Author: | RsX [ Sat Apr 01, 2006 10:45 pm ] |
Post subject: | |
I just downloaded and installed 4.0.4c ![]() View.Update doesnt appear as a variable anymore! Yay! ![]() So to use it I just insert it randomly every few lines? |
Author: | Tony [ Sat Apr 01, 2006 10:56 pm ] |
Post subject: | |
RsX wrote: So to use it I just insert it randomly every few lines?
/slap |
Author: | RsX [ Sat Apr 01, 2006 11:09 pm ] |
Post subject: | |
Does that mean im right? lol |
Author: | RsX [ Sat Apr 01, 2006 11:57 pm ] | ||
Post subject: | |||
Lol... Actually, I learned how to use View.Update and offscreenonly and was able to reduce flickering completely. But still there is the problem with the paddle movement code. I changed some code, because I thought it was unfair to have one player with the mouse and the other struggling with the keyboard, so as you can see I set the main user to use 'A' to move up and 'Z' to move down. Player 2 uses 'K' to move up and 'M' to move down. There are 2 problems with this. 1) The movement is cut off, random, doesnt work at times, slow and inefficient. 2) Player 2 cannot move at all for some reason... Thank you in advance to all those who help!!!
|
Author: | RsX [ Sun Apr 02, 2006 12:02 am ] | ||
Post subject: | |||
Here is more organized code with only the parts I need help with... (In referrence to the post above)
|
Author: | NikG [ Mon Apr 03, 2006 9:35 am ] |
Post subject: | |
The code in both of your posts has MANY errors, so we can't run it if we wanted to check what was wrong. Next time, please post the entire code. Why do you have two if statements (one for each player)? You should be checking for both player's input at the same time. Also, now that you have updated your Turing, switch to Input.Keydown. It's better than getch because it catched multiple button presses (which is necessary if both players will be using the keyboard). |
Author: | do_pete [ Mon Apr 03, 2006 1:15 pm ] | ||
Post subject: | |||
Here's how Input.KeyDown works:
If you have any questions about it, just ask. |