
-----------------------------------
CLPost
Sun Jun 14, 2009 8:14 pm

Keydown Input
-----------------------------------
What is it you are trying to achieve?
A arrow appears at the top of the screen, the user must input the shown arrow and the x variable either increases if they press wrong or decreases if they press right

What is the problem you are having?
I can't seem to make the x variable go up or down in value, when the specific key is pressed


Describe what you have tried to solve this problem
I tried rearranging the code but it hasn't helped much


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)



var key : array char of boolean
var x : int := maxx

proc Level1
    var c : int
    var pic, pic2, pic3, pic4, pic5, pic6, pic7, pic8 : int

        put maxx

        randint (c, 1, 4)

        pic5 := Pic.FileNew ("Left2.jpg")
        pic6 := Pic.FileNew ("Up2.jpg")
        pic7 := Pic.FileNew ("Down2.jpg")
        pic8 := Pic.FileNew ("Right2.jpg")

        if c = 1 then
            Pic.Draw (pic5, maxx div 2, maxy - 90, picMerge)
        elsif c = 2 then
            Pic.Draw (pic6, maxx div 2 + 10, maxy - 100, picMerge)
        elsif c = 3 then
            Pic.Draw (pic7, maxx div 2 + 10, maxy - 100, picMerge)
        else
            Pic.Draw (pic8, maxx div 2, maxy - 90, picMerge)
        end if

        Input.KeyDown (key)

        if key (KEY_LEFT_ARROW) and c = 1 then
            x -= 1
        elsif key (KEY_LEFT_ARROW) and c not= 1 then
            x += 1
        end if
        if key (KEY_UP_ARROW) and c = 2 then
            x -= 1
        elsif key (KEY_UP_ARROW) and c not= 2 then
            x += 1
        end if
        if key (KEY_DOWN_ARROW) and c = 3 then
            x -= 1
        elsif key (KEY_DOWN_ARROW) and c not= 3 then
            x += 1
        end if
        if key (KEY_RIGHT_ARROW) and c = 4 then
            x -= 1
        elsif key (KEY_RIGHT_ARROW) and c not= 4 then
            x += 1
        end if

        delay (1500)

        Pic.Free (pic5)
        Pic.Free (pic6)
        Pic.Free (pic7)
        Pic.Free (pic8)

        cls
        
end Level1

loop
    Level1
    Input.KeyDown (key)
end loop




Please specify what version of Turing you are using
4.1.1

-----------------------------------
BigBear
Sun Jun 14, 2009 8:27 pm

RE:Keydown Input
-----------------------------------
you are changing the value of x but you are not doing anything with it try putting it instead of maxx

-----------------------------------
TheGuardian001
Sun Jun 14, 2009 8:30 pm

Re: Keydown Input
-----------------------------------
In the future, if your code has images, include the images. We can't run your code if we don't have them. 

So, with the knowledge that I couldn't actually run your program and that I'm totally guessing here, I would say that the problem is that you never actually use the variable "x". Ever.

You change it with the arrow keys, but you aren't drawing based on "x", and you never use it outside of the input checking, so why would anything change? Your drawing code:


if c = 1 then 
    Pic.Draw (pic5, maxx div 2, maxy - 90, picMerge) 
elsif c = 2 then 
    Pic.Draw (pic6, maxx div 2 + 10, maxy - 100, picMerge) 
elsif c = 3 then 
    Pic.Draw (pic7, maxx div 2 + 10, maxy - 100, picMerge) 
else 
    Pic.Draw (pic8, maxx div 2, maxy - 90, picMerge) 
end if 


Why are you saying to draw at "maxx div 2 + 10" if you want it to draw at "x"?


EDIT: Ninja'd by BigBear :(

-----------------------------------
CLPost
Sun Jun 14, 2009 8:32 pm

RE:Keydown Input
-----------------------------------
my bad i just noticed that I was putting maxx instead of the x var...... my bad guys thanks for your help

-----------------------------------
BigBear
Sun Jun 14, 2009 8:35 pm

RE:Keydown Input
-----------------------------------
Also in your main loop you are calling Input.KeyDown (key)
and then calling again in your proc so the one in your main loop isn't being evaluated

You should be using parameter lists or just having one loop so you are not declaring and assigning variables everytime.

-----------------------------------
CLPost
Sun Jun 14, 2009 8:39 pm

RE:Keydown Input
-----------------------------------
actually is there anyway to improve the reposiveness of the inputs cause im spaming it and it only reacts 1/10 times =S

-----------------------------------
CLPost
Sun Jun 14, 2009 8:41 pm

RE:Keydown Input
-----------------------------------
nevermind im dumb.... i just had to change the delay my bad again

-----------------------------------
BigBear
Sun Jun 14, 2009 8:43 pm

Re: Keydown Input
-----------------------------------
I don't know why you have eight different variables for picture. You are only using 3.

If you renamed your images you could have 

var c := Rand.Int(1, 4)
var pic : int := Pic.FileNew ("Picture" + intstr (c) + ".jpg")
%Where each picture is name Picture1.jpg, Picture2.jpg etc

-----------------------------------
CLPost
Sun Jun 14, 2009 8:58 pm

RE:Keydown Input
-----------------------------------
er the 8 different variables were for later parts of the program =S i guess i could use the "pic" intstr "jpg" thing but usually i only use it for picnum =S
