Key Jamming speeds up the program, this is a problem........ 
	 
	
		| Author | 
		Message | 
	 
		 
		namby_trojan
 
 
 
    
		 | 
		
		
			
				  Posted: Tue May 20, 2008 5:48 pm    Post subject: Key Jamming speeds up the program, this is a problem........  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				Hi, I've been working on this typing program (started off today) and I've ran into a problem.
 
 
I move the text down using pixels and I use getch command to get the character. But the more characters you type, the faster the program becomes. Being said, it also becomes very flickery. The fastest way to see it if you jam the keys. I've been checking all of the variables and i cannot find what's responsible for this. Help? pl0x ? Here's the code.
 
 
Quote: 
 
setscreen ("graphics:600;600,nobuttonbar")
 
 
 
var pic : int
 
var ch : string (1)
 
var num : int := 11 %equals to number of words
 
var num1 : int := 11
 
var dic : array 1 .. 11 of string
 
dic (1) := "John"
 
dic (2) := "Johny"
 
dic (3) := "Somethingdiffarat"
 
dic (4) := "Fatt"
 
dic (5) := "Bobby"
 
dic (6) := "Car"
 
dic (7) := "Blank"
 
dic (8) := "Wank"
 
dic (9) := "Crap"
 
dic (10) := "Imagination"
 
dic (11) := "nithing"
 
var long, m, another, o : int := 1
 
var check : string
 
var font1 := Font.New ("arial:20:bold,italic")
 
var n : int := 2
 
 
process shoot
 
    Music.PlayFile ("MetalBang.wav")
 
end shoot
 
 
 
 
randint (num, 1, 11) %Randomizes the number
 
process text
 
 
    loop
 
 
 
 
        Draw.Text (dic (num), maxx div 2, maxy - m, font1, gray) %draws text
 
        delay (100)
 
        Draw.Text (dic (num), maxx div 2, maxy - m, font1, white) %erases text
 
    
 
        if m = 350 then
 
            m := 0         %<-----------create a loop..........just restarts from top
 
        end if
 
        m := m + 1
 
 
 
        exit when m = maxy or another = 2 %check if the word was fin1ished or not aka another=2 is word finished
 
 
 
 
    end loop
 
    if another = 2 then      
 
    
 
        m := 0             %basically resets the word so you can start with another one      
 
        another := 1
 
        randint (num, 1, 11)
 
        n := 2
 
 
        fork text 
 
end if
 
 
end text
 
 
 
 
 
loop
 
    fork text
 
    getch (ch)
 
    Time.Delay (100)
 
    cls
 
    delay (50)
 
 
    if ch = dic (num) (1) %<----------works only w/ 1st letter, I had multiple words b4, this was a way of distinguishing between them
 
            then
 
 
 
        long := length (dic (num)) %<----gets the length of a word
 
        for count : 2 .. long %<-----------starts off 2 because first letter is given already
 
 
            check := dic (num) (n)
 
            getch (ch)
 
            Time.Delay (100)  %attempted to stop the key jamming, still doesn't work
 
 
        
 
            %put ch ..
 
            if ch = check
 
 
                    then
 
                fork shoot       %that's the sound
 
                n := n + 1
 
 
                if n = long + 1 %if the letter is correct, but then further if the length is met, then the word is complete
 
                        then
 
                    %put "the word was corret 100%"
 
                    another := another + 1
 
                end if
 
            else
 
                %put "incorrect"
 
            end if
 
            m := m + 1
 
        end for
 
 
    end if
 
 
end loop
 
 
%if the keys ar ejammed, it all ADDS up.................
 
  | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
		 
		Sponsor Sponsor 
		 
  
		 | 
		
 | 
	 
	 
		  | 
	 
				 
		gitoxa
 
  
 
    
		 | 
		
		
			
				  Posted: Tue May 20, 2008 8:52 pm    Post subject: RE:Key Jamming speeds up the program, this is a problem........  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| My first suggestion is to re-write it, not using processes.   They are rather buggy (in Turing), and have been known to cause problems. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		namby_trojan
 
 
 
    
		 | 
		
		
			
				  Posted: Wed May 21, 2008 2:25 pm    Post subject: RE:Key Jamming speeds up the program, this is a problem........  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				that's a great idea, except I don't know how to make a program that doesn't pause at the "get" command. 
 
 
Any help? Thanks. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		Sean
 
  
 
    
		 | 
		
		
			
				  Posted: Wed May 21, 2008 2:58 pm    Post subject: Re: Key Jamming speeds up the program, this is a problem........  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| get statements always require input. You are getting the user input, and will always stop until you enter something. Use Procedures instead of Processes. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		gitoxa
 
  
 
    
		 | 
		
		
			
				  Posted: Wed May 21, 2008 3:24 pm    Post subject: RE:Key Jamming speeds up the program, this is a problem........  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				Sean, run his program first.  
 
 
I know the Input.KeyDown doesn't pause the program while waiting for a letter, but implementing it could a pain.  Does anyone else have any ideas? | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		StealthArcher
 
  
 
    
		 | 
		
		
			
				  Posted: Wed May 21, 2008 3:44 pm    Post subject: Re: Key Jamming speeds up the program, this is a problem........  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
					  | Turing: | 	 		  
process text
     loop
        Draw.Text (dic  (num ), maxx div 2,  maxy - m, font1,  gray) %draws text
        delay (100)
        Draw.Text (dic  (num ), maxx div 2,  maxy - m, font1,  white) %erases text
        if m  = 350 then
            m  := 0         %<-----------create a loop..........just restarts from top
        end if
        m  := m +  1
        exit when m  = maxy or another  = 2 %check if the word was fin1ished or not aka another=2 is word finished
    end loop
    if another  = 2 then      
       m  := 0             %basically resets the word so you can start with another one      
        another  := 1
        randint (num,  1,  11)
        n  := 2
        [b ]fork text [/b ] 
end if
end text
   | 	  
 
 
I'm jut quickly glancing, but why is it, in the process "text" (it's true though, you really shouldn't use processes) there is a command to start forking itself?  That would cause it to do almost nothing but text the longer your program ran.
 
 
EDIT: Checked it, this does solve the problem.  Simple mistake. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		namby_trojan
 
 
 
    
		 | 
		
		
			
				  Posted: Wed May 21, 2008 5:18 pm    Post subject: RE:Key Jamming speeds up the program, this is a problem........  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				Thanks for your all replies.
 
@Stealth - well, I tried removing the fork and jamming the keys   and it still speeded up. I am starting to wonder if the game speeds up according to the length of its current word aka the more you type the faster it goes.
 
 
And I used to have that fork because I had this problem when I was having 2 words at the same time...forgot how I used it though.
 
 
Thanks, does anyone else have any solutions  
 
 
Btw, is this actually the crappy use of processes or I am making a logical mistake or something ? Also @gitoxa, yeah that Input.Keydown seems interesting, but since it's a "different" operands as turing says, I cannot see if it equals the string. Other than that I guess that coulda work, just needed to change a few loops.... | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		andrew.
 
 
 
    
		 | 
		
		
			
				  Posted: Sat May 24, 2008 8:45 pm    Post subject: RE:Key Jamming speeds up the program, this is a problem........  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				Well, I'd just like to give a few pointers that will help your code with this problem and will help overall.
 
 
1. Do not use processes unless it's for sound.
 
2. Try to put everything into one main loop. If it gets messy then use a procedure.
 
3. Try re-writing your code. Save it as a different file so you don't lose your original if you mess up. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
		 
		Sponsor Sponsor 
		 
  
		 | 
		
 | 
	 
	 
		  | 
	 
				 
		 | 
	 
 
	
	
	 
	
	 |