code erorr

Started by
3 comments, last by joey81 22 years, 2 months ago
if (keys['' ''] && !sp) { sp=TRUE; object++; if(object>5) object=0; } if (!keys['' '']) { sp=FALSE; } if (keys[VK_PRIOR]) { z-=0.02f; } if (keys[VK_NEXT]) { z+=0.02f; } if (keys[VK_UP]) { xspeed-=0.01f; } if (keys[VK_DOWN]) { xspeed+=0.01f; } if (keys[VK_RIGHT]) { yspeed+=0.01f; } if (keys[VK_LEFT]) { yspeed-=0.01f; } if (keys[''t''] && !tp) { tp=TRUE; while(xspeed!=0.00f) { xspeed=0.00f; } while(yspeed!=0.0f) { yspeed=0.00f; } } if (!keys[''t'']) { tp=FALSE; } Hi, I''m using Nehe''s Quadratic tutorial here. Ok. My problem is that when the image is rotating after the arrow keys are pressed, i want to stop the rotation by pressing the ''t'' key. But i cant seem to get it.... What''s wrong with my coding?? Can anyone help??? Thanks in advance....
Advertisement
Have you tried changing ''t'' to ''T''?
I''m not sure whether that will make a difference, but give it a go. If you still can''t get it working, try making it a different key, like backspace or something (VK_DELETE)...

--Samah
All key commands must be in capitals in order for them to work so..

if (keys[''t''] && !tp) becomes if (keys[''T''] && !tp)

Plus I dont see the code that relates to when ''T'' is pressed except the tp code. To stop the object put this under the T key code.

if (keys[''T''] && !tp){

z=0.0f;
xspeed=0.0f;
yspeed=0.0f;
}

Plus I dont think you need the following


/*these would seem to loop to infinity unless you had a thread going to exit*/

while(xspeed!=0.00f)
{
xspeed=0.00f;
}

while(yspeed!=0.0f)
{
yspeed=0.00f;
}
I''ve got it!!
Thanks alot for your help!!
for coding purposes you don''t even need this
  if (keys[''T''] && !tp){ tp=TRUE; xspeed=0.00f; yspeed=0.00f;}if (!keys[''T'']){ tp=FALSE;}  


Quicker to do this

  if(keys[''T'']) xspeed=yspeed=0.0f;  


Less processing, neater, and much easier to debug.
You do not need the "T press" checking as it isn''t a toggle switch, just a push button.



Beer - the love catalyst
good ol'' homepage
Beer - the love catalystgood ol' homepage

This topic is closed to new replies.

Advertisement