Computer Science Canada Boolean Parameter |
Author: | Mr. T [ Mon Jun 12, 2006 11:07 pm ] | ||
Post subject: | Boolean Parameter | ||
I tried setting up a boolean parameter in the hopes that I could make the box continue by itself in the direction pressed, but to no avail. I understand where the problem lies...in the fact that the boolean is only true the instant the key is down...but I can't think of any solutions. I know could fix the problem by eliminating the procedure move, but I want to keep it in. So any ideas how I can solve my problem?
|
Author: | NikG [ Tue Jun 13, 2006 12:18 am ] |
Post subject: | |
Well, the move proc seems really pointless... but if you insist on keeping it, you can add a string variable called direction or whatever. Have the value of it change when there's a key press. Meanwhile, just insert another if statement above your ball proc and pass your booleans to move based on the value of direction (although the better solution is to just get rid of move and use that new if statement above ball to change the a/b values). |
Author: | TheOneTrueGod [ Tue Jun 13, 2006 6:13 am ] | ||
Post subject: | |||
The handy thing about Input.KeyDown is it is an array char of boolean. if you noticed, in your if statements, your actually checking to see if that specific char is true, so why not directly call move with chars? Also, You shouldn't use global variables. Pass the ball's co-ordinates (I'm going to assume "a" and "b") as variable parameters. |
Author: | TheOneTrueGod [ Tue Jun 13, 2006 6:15 am ] |
Post subject: | |
Sorry for the double post, but I remembered something else that I should mention. Doing it this way (in a procedure) is actually better, because it makes it so you don't have to hard code the movement values as much, and so you can have two balls being controlled by separate keys, but with one procedure (assuming you pass the co-ordinates as variables). This also makes things like getting user opted controls fairly easier. |
Author: | Delos [ Tue Jun 13, 2006 9:00 am ] | ||
Post subject: | |||
Well in a comment a little more related to your problem, if you want to have the ball continuously travelling in a specific direction, then set yourself up some vector maths. You could create a ball type:
And in your movement proc, set the values of (dX, dY) to whatever you need. During your draw_ball proc, you'd add dX to x and dY to y, creating the necassary movement. |
Author: | Mr. T [ Tue Jun 13, 2006 12:16 pm ] | ||||
Post subject: | Alex's Opinion | ||||
TheOneTrueGod wrote:
The handy thing about Input.KeyDown is it is an array char of boolean. if you noticed, in your if statements, your actually checking to see if that specific char is true, so why not directly call move with chars? Also, You shouldn't use global variables. Pass the ball's co-ordinates (I'm going to assume "a" and "b") as variable parameters. Here's my new code. I've been unable to implement both your suggestions. Can you show me how I might be able to both because I would like to eliminate the number of boolean vars, and I would like to eliminate as many global vars as possible.
|
Author: | Clayton [ Tue Jun 13, 2006 4:45 pm ] | ||
Post subject: | |||
just eliminate all of the boolean values being set to whatever and go with TOTG's idea, after your Input.Key down just do this
and have a global variable that controls which key was pressed in your if statements in your move proc, or something along those lines |