auto keyhit?

Blitz3D Forums/Blitz3D Beginners Area/auto keyhit?

war_god1230(Posted 2006) [#1]
.label
If Keyhit (44)
;some sorta loop comamnd
Endif
Goto


i trying to make the keyhit repeat. so instaed of haveing to take your finger up it will just repeat, or as soon as it been pushed once then it repeats ovre and over it the progame runs out.


Stevie G(Posted 2006) [#2]
Both KeyHit and Keydown are detecting key presses and return True or False, you cannot force Blitz to do it for you.

I assume you want some sort of delay so that the player can't keep their finger on a key? Something like this may work for you ...

global KeyTimer=0

if Keydown(44) and KeyTimer = 0
   KeyTimer = 100
   ;do stuff
else
  KeyTimer = KeyTimer - ( KeyTimer > 0 )
endif


Otherwise I think you need to explain yourself a bit better?

Stevie


war_god1230(Posted 2006) [#3]
thank you but what i trying to figer out is how to make the computer reppeat a command i issue. if i tell it to hitkey then i want it to do that in a loop.


mindstorms(Posted 2006) [#4]
Try keydown? It will return whether the key is currently down. Keyhit only returns true the first time a key is pressed (key has to be released before anything more will happen)


Stevie G(Posted 2006) [#5]
Using keydown won't make a difference as it will not stop anything from happening whether it's detected or not.

I noticed you've now edited your code.

Still don't understand why you'd want to do this - put you're question in a gaming context. This will go into a continous loop until escape is pressed.

If keyhit( 44 )

  repeat : until keydown(1)

endif


Stevie


Sir Gak(Posted 2006) [#6]
I wonder if what he is trying to do is to keep taking the command for as long as the key is being pressed, but stop when the key is released. This is found, for instance, in old classic games like Ultima 3, where you move in a certain direction for as long as you hold the key down, and stop when you release the key. Makes it easier than, say, having to press the key, release, press, release, etc, ad nauseum.


war_god1230(Posted 2006) [#7]
sorry if i confused any one the problem is i dont know exaly how to do it so i can only ask a broad qwuestion. but stevie g sorta got what i was trying to get and sir gak got it on the haed if only he would have told me how to do it. so if any one looks at this sir gak is right i just need to know how to do it. plz and thank you, also thank you to all who tried to help.


mindstorms(Posted 2006) [#8]
then all you need to do is to say if keydown(the_key) then do the movement. When the key is released it will not execute...this is how most programs do it.

an example from the docs:


; MoveEntity Example 
; ------------------ 

Graphics3D 640,480 
SetBuffer BackBuffer() 

camera=CreateCamera() 
light=CreateLight() 

cone=CreateCone( 32 ) 

; Move cone in front of camera, so we can see it to begin with 
MoveEntity cone,0,0,10 

While Not KeyDown( 1 ) 

; Reset movement values - otherwise, the cone will not stop! 
x#=0 
y#=0 
z#=0 

; Change rotation values depending on the key pressed 
If KeyDown( 203 )=True Then x#=-0.1 
If KeyDown( 205 )=True Then x#=0.1 
If KeyDown( 208 )=True Then y#=-0.1 
If KeyDown( 200 )=True Then y#=0.1 
If KeyDown( 44 )=True Then z#=-0.1 
If KeyDown( 30 )=True Then z#=0.1 

; Move cone using movement values 
MoveEntity cone,x#,y#,z# 

; If spacebar pressed then rotate cone by random amount 
If KeyHit( 57 )=True Then RotateEntity cone,Rnd( 0,360 ),Rnd( 0,360 ),Rnd( 0,360 ) 

RenderWorld 

Text 0,0,"Use cursor/A/Z keys to move cone, spacebar to rotate cone by random amount" 
Text 0,20,"X Movement: "+x# 
Text 0,40,"Y Movement: "+y# 
Text 0,60,"Z Movement: "+z# 

Flip 

Wend 

End 



war_god1230(Posted 2006) [#9]
ok that should work, i also got another reply on dif site if any intressted it say to use keyhit and put a delay on it so it checks if the key is down every so often then if it is it exacutes the progame in what ever way. works the same as keydown i guess. ty every once again.