Author |
Message |
nick4563
|
Posted: Wed Jan 12, 2011 2:25 pm Post subject: HELP!!! Making an if key pressed statement execute repeatedly after pressing the key only once!? |
|
|
What is it you are trying to achieve?
I am trying to make a conditional loop repeat several times after a key has been pressed
What is the problem you are having?
Doesnt Work!!!! (What a stupid question)
Describe what you have tried to solve this problem
Everything I Know... i need to make my bullet shoot after pressing the '1' key once i can do everything but the weird loop.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Please specify what version of Turing you are using
4.1
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Wed Jan 12, 2011 2:49 pm Post subject: RE:HELP!!! Making an if key pressed statement execute repeatedly after pressing the key only once!? |
|
|
You could try remembering (in some variable) if a key has been pressed in the past. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
TheCatsMeow
|
Posted: Wed Jan 12, 2011 5:50 pm Post subject: RE:HELP!!! Making an if key pressed statement execute repeatedly after pressing the key only once!? |
|
|
You could try putting a boolean in there. and make it "True" when the key is pressed, but false when no keys are pressed. |
|
|
|
|
|
chaos
|
Posted: Wed Jan 12, 2011 6:32 pm Post subject: Re: HELP!!! Making an if key pressed statement execute repeatedly after pressing the key only once!? |
|
|
Try this:
if key(1) then
capture bullet position
boolean variable=true
end if
if boolean variable=true then
move bullet
draw bullet
end if |
|
|
|
|
|
nick4563
|
Posted: Wed Jan 12, 2011 7:24 pm Post subject: Re: HELP!!! Making an if key pressed statement execute repeatedly after pressing the key only once!? |
|
|
Thanks! I never thought of using a boolean to control the loop! |
|
|
|
|
|
nick4563
|
Posted: Thu Jan 13, 2011 1:37 pm Post subject: Re: HELP!!! Making an if key pressed statement execute repeatedly after pressing the key only once!? |
|
|
I have this code:
var chars : array char of boolean
var a,b : int a:= 20 b:= 20
var shoot : boolean
drawfilloval(a,b,20,2,green)
loop
drawfilloval(a,b,20,2,green)
Input.KeyDown (chars)
if chars ('1')then
shoot:=true
else
shoot:=false
end if
if
true then
drawfilloval(a,b,20,2,green)
a+=10
delay(10)
end if
cls
end loop
Why does it shoot automatically not when the 1 key is pressed
I am not looking ofr code handouts only help ... |
|
|
|
|
|
Tony
|
Posted: Thu Jan 13, 2011 2:10 pm Post subject: RE:HELP!!! Making an if key pressed statement execute repeatedly after pressing the key only once!? |
|
|
What condition does your code say needs to happen, for the shot to fire? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
nick4563
|
Posted: Thu Jan 13, 2011 2:18 pm Post subject: Re: HELP!!! Making an if key pressed statement execute repeatedly after pressing the key only once!? |
|
|
I think it says that shhot needs to be true to fire the bulllet... At least that was what i was going for. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
nick4563
|
Posted: Thu Jan 13, 2011 2:19 pm Post subject: Re: HELP!!! Making an if key pressed statement execute repeatedly after pressing the key only once!? |
|
|
I think it says that shhot needs to be true to fire the bulllet... At least that was what i was going for. |
|
|
|
|
|
nick4563
|
Posted: Thu Jan 13, 2011 2:26 pm Post subject: RE:HELP!!! Making an if key pressed statement execute repeatedly after pressing the key only once!? |
|
|
if
**true then
drawfilloval(a,b,20,2,green)
a+=10
delay(10)
end if
**this is the section of code that is supposed to make the bullet appear and then shoot when shoot=true** |
|
|
|
|
|
Tony
|
Posted: Thu Jan 13, 2011 2:29 pm Post subject: Re: RE:HELP!!! Making an if key pressed statement execute repeatedly after pressing the key only once!? |
|
|
nick4563 @ Thu Jan 13, 2011 2:26 pm wrote: if
**true then
drawfilloval(a,b,20,2,green)
a+=10
delay(10)
end if
Where does this mention the "shoot" variable? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
DemonWasp
|
Posted: Thu Jan 13, 2011 2:50 pm Post subject: RE:HELP!!! Making an if key pressed statement execute repeatedly after pressing the key only once!? |
|
|
You never use the value of the shoot variable to do anything. You need to, depending on that value, either shoot or not shoot. |
|
|
|
|
|
nick4563
|
Posted: Fri Jan 14, 2011 1:34 pm Post subject: Re: HELP!!! Making an if key pressed statement execute repeatedly after pressing the key only once!? |
|
|
Here is my new code for the bullet...
am using the values x2 and y1 for a and b so that the bullet shoots from the players box (I know using a box for a character is LAME but im a noob)
The bullet goes ten pixels in front of the character and then follows him, How do i get rid of that.
Turing: |
var a : int := x2
var b : int := y1
if chars ('1') then %bullet shoots only when shoot = true
shoot := true
end if
if shoot = true then
a + = 10
drawfilloval (a, b, 10, 10, red)
delay (5)
end if
if a > 389 then % sets bullet back after reaching the end of the screen
shoot := false
end if
|
%I also have this seperate bullet code that works
Turing: |
var shoot : boolean
shoot := false
var chars : array char of boolean
var a : int := 20
var b : int := 20
loop
Input.KeyDown (chars )
if chars ('1') then
shoot := true
end if
if shoot = true then
a += 10
drawfilloval (a, b, 20, 2, green)
delay (10)
cls
end if
end loop
|
|
|
|
|
|
|
Tony
|
Posted: Fri Jan 14, 2011 1:54 pm Post subject: Re: HELP!!! Making an if key pressed statement execute repeatedly after pressing the key only once!? |
|
|
nick4563 @ Fri Jan 14, 2011 1:34 pm wrote:
The bullet goes ten pixels in front of the character and then follows him, How do i get rid of that.
I would imagine that you are using your character's position to figure out the bullets position; which doesn't make sense after the bullet has been fired. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
nick4563
|
Posted: Fri Jan 14, 2011 6:37 pm Post subject: RE:HELP!!! Making an if key pressed statement execute repeatedly after pressing the key only once!? |
|
|
How would I be able to have the bullet originate at the characters position but progress away once shot?? |
|
|
|
|
|
|