C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 6th, 2006, 02:07 PM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
"Key" problem - Please Help

Hi to all,

Well, I want to see if a key is pressed, so I use GetAsyncKeyState(short key_code). I put if the key pressed is '2' then call a function. In that function I put also if the key pressed is '2' to do something. Well, when I press 2 in the first function, the 2 is "pressed" in the other function too.

Here's the parts of my code to help you understand what the problem is:
Code:
// in the first function
if(GetAsyncKeyState('2'))
	{
		Buy(); // Call next function
	}

//In the "other" function
while(c != 'q')
			{
				if(GetAsyncKeyState('1'))
				{
				int r;
				r=you.money;
				int u;
				u=r-50;
				if (u>=0)
				{
					you.setmoney(u);
					bouv++;
					you.getattack(10);
					cout<<"\nAdded 10 points to your attack.";
					c = 'q'; // it seems like it doesn't understand this and continues -- NOT a big problem
					break;
				}
				else
				{
					cout<<"\nYou cannot afford to buy this sword.";
					c = 'q';
					break;
				}
				}
				if(GetAsyncKeyState('2')) // it seems like it gets the key state from the previous function and when this function is called it executes the part of code in this if statement -- BIG PROBLEM(MY PROB)
				{
				int w;
				w=you.money;
				int s;
				s=w-60;
				if (s>=0)
				{
					you.setmoney(s);
					bouv++;
					you.getdefence(10);
					cout<<"\nAdded 10 points to your defence skills.";
					c = 'q'; // it seems like it doesn't understand this and continues -- NOT a big problem
					break;
				}
				else
				{
					cout<<"\nYou cannot afford to buy this armory.";
					c = 'q';
					break;
				}
				}
				if(GetAsyncKeyState('3'))
				{
					c = 'q';
				return 0;
				}
			}
		}


Can I "erase"/"reset" the GetAsyncKeyState Value or something? Any help would be appreciated!!

Thanks in advance!!

Costas

Reply With Quote
  #2  
Old October 7th, 2006, 02:35 AM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
Anyone? I need that information-help!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > "Key" problem - Please Help


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap