Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Remapping controls to be used with Input.KeyDown
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Mongoose




PostPosted: Sat May 27, 2006 8:01 pm   Post subject: Remapping controls to be used with Input.KeyDown

I'm making a pong game with some extra features such as items and remappable controls. The controls are easy enough to reset if I use the getch command, but the game runs better using Input.KeyDown (it isn't smooth when you hold down a key with the getch command). Is there any way to let Input.KeyDown recognize a key that is a variable?

I tried:
code:
Input.KeyDown (button)
if button (p1Up) then
y (1) := y (1) + 10
end if


where p1Up was a string (1) that you could set before. I get the error "Array subscript out of range". Is it not possible to do this sort of thing, or am I overlooking something stupid?
I would appreciate any help or advice.
Sponsor
Sponsor
Sponsor
sponsor
MysticVegeta




PostPosted: Sat May 27, 2006 8:06 pm   Post subject: (No subject)

Sure there is a way!!! Smile
Well you see, the argument for the Input.KeyDown array is either a char or "KEY_WHATEVER" (without the quotes) so there are various scenerios possible, for eg:

code:
var key : char := 't'
var key2 := KEY_ENTER

var chars : array char of boolean
loop
    Input.KeyDown (chars)
    locate (1, 1)
    if chars (key) then
        put key, " Pressed  "
    elsif chars (key2) then
        put "Enter Pressed "
    end if
end loop
Cervantes




PostPosted: Sat May 27, 2006 8:30 pm   Post subject: (No subject)

MysticVegeta: I think he knows that much. The point is not to hardcode the values for the keys, as you have done.

Mongoose: You can use getch (or better yet, getchar) for that one section of the code only where you set the controls, then use Input.KeyDown for the rest of the program.

code:

put "Please enter a key for Player 1: " ..
var p1Up := getchar

delay (100)

var keys : array char of boolean
loop
    locate (1, 1)
    Input.KeyDown (keys)
    if keys (p1Up) then
        put "Player 1 is moving upwards."
    else
        put ""
    end if
end loop
MysticVegeta




PostPosted: Sat May 27, 2006 8:53 pm   Post subject: (No subject)

If you read his post, he was using the type string(1) for p1Up which obviously doesnt work since string(1) not= char. His point from my opinion was that he was trying to pass a variable into Input.KeyDown
Mongoose




PostPosted: Sat May 27, 2006 9:19 pm   Post subject: (No subject)

Ah, excellent. It works. The problem was simple; the string (1)s needed to be chars, as you said. Thanks very much for the help guys, cripes that was quick.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: