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

Username:   Password: 
 RegisterRegister   
 why this on work?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Uber Tankz




PostPosted: Fri Jun 09, 2006 7:34 am   Post subject: why this on work?

aight here, ive got the Input.KeyDown thinger and arrgggg now its just retarted. I have it so when a key is presssed it adds 10 points to the score but this adds like 1000. why? and how can i fix? another thing how can i make it so that it only adds to the score if a certain procedure was the last one to be called?

code:
var chars : array char of boolean
var score : int
score := 0

loop
    Input.KeyDown (chars)

    if chars (KEY_UP_ARROW) then
        score := score + 10
    end if
    if chars (KEY_RIGHT_ARROW) then
        score := score + 10
    end if
    if chars (KEY_LEFT_ARROW) then
        score := score + 10
    end if
    if chars (KEY_DOWN_ARROW) then
        score := score +10
    end if
   
    locate (1, 70)
    put score

end loop
Sponsor
Sponsor
Sponsor
sponsor
Remm




PostPosted: Fri Jun 09, 2006 8:37 am   Post subject: (No subject)

Ok, this is what i think it is. when you click it, it regesters it so many times in the time it takes you to take your finger back off, that it looks like that. Try adding some massive delays so it cant be spammed. I don have turing atm so i cant try it Confused
HellblazerX




PostPosted: Fri Jun 09, 2006 10:15 am   Post subject: (No subject)

Don't use delays. That's very inefficient. Use a boolean flag. Basically, you make it in your if statements so it will only add the score if the boolean is false, and after you add the score, make the boolean true. You make the boolean false only when the player is not pressing any buttons.
Remm




PostPosted: Fri Jun 09, 2006 1:36 pm   Post subject: (No subject)

Not the first time ive heard that
haha im like the god of inefficientcy
TheOneTrueGod




PostPosted: Fri Jun 09, 2006 2:26 pm   Post subject: (No subject)

And this isn't the first time i've pointed this out either. The boolean flag way, while it works for one, or maybe two different statements, will not work if you have, say, 10 keys being pressed. Thats 10 different boolean variables that you have to declare, intialize, and keep track of. Very inefficient, not to mention that you'll run out of descriptive names eventually.

What you should do is have a second "keys" variable. A la:

code:

var keys,oldkeys : array char of boolean
Input.KeyDown(keys) %So we don't get a "no value" error
loop
oldkeys := keys
Input.KeyDown(keys)

if keys('a') and not oldkeys('a') then
%This is when the 'a' key was "freshly" pressed.  Sounds like orange Juice...
end if

end loop


Its a lot simpler to keep track of, and you don't have to worry about forgetting to rese the boolean variable. Its also much simpler to manage 10-20 different keystrokes.
Hack.saw




PostPosted: Fri Jun 09, 2006 7:41 pm   Post subject: (No subject)

when u press a key down it counts every mili second the key is pressed so you will need to use a flag to make sure it only counts the first one.
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  [ 6 Posts ]
Jump to:   


Style:  
Search: