• Advertisement
Sign in to follow this  

Can you see whats wrong?

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I dont know why it doesnt work. It should take m_chat_key and add it to m_chat_msg. And create a long string which is then sent to the server. But for some reason m_chat_msg is only coming out as what ever key I pressed last. Anyone see whats wrong?
  if(m_Chat == TRUE){
	  if(m_Keyboard.GetKeyState(KEY_A) == TRUE){
			strcpy (m_Chat_Key,"A");
	  }
	  if(m_Keyboard.GetKeyState(KEY_B) == TRUE){
			strcpy (m_Chat_Key,"B");
	  }
	  if(m_Keyboard.GetKeyState(KEY_C) == TRUE){
			strcpy (m_Chat_Key,"C");
	  }
	  if(m_Keyboard.GetKeyState(KEY_D) == TRUE){
			strcpy (m_Chat_Key,"D");
	  }
	  if(m_Keyboard.GetKeyState(KEY_E) == TRUE){
			strcpy (m_Chat_Key,"E");
	  }
	  if(m_Keyboard.GetKeyState(KEY_F) == TRUE){
			strcpy (m_Chat_Key,"F");
	  }
	  if(m_Keyboard.GetKeyState(KEY_G) == TRUE){
			strcpy (m_Chat_Key,"G");
	  }
	  if(m_Keyboard.GetKeyState(KEY_H) == TRUE){
			strcpy (m_Chat_Key,"H");
	  }
	  if(m_Keyboard.GetKeyState(KEY_I) == TRUE){
			strcpy (m_Chat_Key,"I");
	  }
	  if(m_Keyboard.GetKeyState(KEY_J) == TRUE){
			strcpy (m_Chat_Key,"J");
	  }
	  if(m_Keyboard.GetKeyState(KEY_K) == TRUE){
			strcpy (m_Chat_Key,"K");
	  }
	  if(m_Keyboard.GetKeyState(KEY_L) == TRUE){
			strcpy (m_Chat_Key,"L");
	  }
	  if(m_Keyboard.GetKeyState(KEY_M) == TRUE){
			strcpy (m_Chat_Key,"M");
	  }
	  if(m_Keyboard.GetKeyState(KEY_N) == TRUE){
			strcpy (m_Chat_Key,"N");
	  }
	  if(m_Keyboard.GetKeyState(KEY_O) == TRUE){
			strcpy (m_Chat_Key,"O");
	  }
	  if(m_Keyboard.GetKeyState(KEY_P) == TRUE){
			strcpy (m_Chat_Key,"P");
	  }
	  if(m_Keyboard.GetKeyState(KEY_Q) == TRUE){
			strcpy (m_Chat_Key,"Q");
	  }
	  if(m_Keyboard.GetKeyState(KEY_R) == TRUE){
			strcpy (m_Chat_Key,"R");
	  }
	  if(m_Keyboard.GetKeyState(KEY_S) == TRUE){
			strcpy (m_Chat_Key,"S");
	  }
	  if(m_Keyboard.GetKeyState(KEY_T) == TRUE){
			strcpy (m_Chat_Key,"T");
	  }
	  if(m_Keyboard.GetKeyState(KEY_U) == TRUE){
			strcpy (m_Chat_Key,"U");
	  }
	  if(m_Keyboard.GetKeyState(KEY_V) == TRUE){
			strcpy (m_Chat_Key,"V");
	  }
	  if(m_Keyboard.GetKeyState(KEY_W) == TRUE){
			strcpy (m_Chat_Key,"W");
	  }
 	  if(m_Keyboard.GetKeyState(KEY_X) == TRUE){
			strcpy (m_Chat_Key,"X");
	  }
	  if(m_Keyboard.GetKeyState(KEY_Y) == TRUE){
			strcpy (m_Chat_Key,"Y");
	  }
	  if(m_Keyboard.GetKeyState(KEY_Z) == TRUE){
			strcpy (m_Chat_Key,"Z");
	  }
	  
	  strcat (m_Chat_Msg, m_Chat_Key);
	  strcpy (m_Chat_Key, "");

	  if(m_Keyboard.GetKeyState(KEY_ENTER) == TRUE){
			m_Chat = FALSE;
	  sChatMessage Msg;
      Msg.Header.Type     = MSG_CHAT;
      Msg.Header.Size     = sizeof(sChatMessage);
      Msg.Header.PlayerID = m_Players[0].dpnidPlayer;
      Msg.ChatMsg[128]         = m_Chat_Msg[128];
      
      // Send message to server
      SendNetworkMessage(&Msg, DPNSEND_NOLOOPBACK);
	  strcpy (m_Chat_Msg, "");
	  }
	
  }else{

	  if(m_Keyboard.GetKeyState(KEY_Y) == TRUE){
	  m_Chat = TRUE;
	  strcpy (m_Chat_Msg, "");
	  Count = 0;

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
m_The m_Goggles m_do m_Nothing!

Share this post


Link to post
Share on other sites
That is my send to server command Msg.ChatMsg[128] is the message that the server will receive. This problem is happening before it is sent. The m_googles are there for organization thats not my issue.

Share this post


Link to post
Share on other sites
Quote:
Original post by LittleFreak
That is my send to server command Msg.ChatMsg[128] is the message that the server will receive. This problem is happening before it is sent.
Translation: no.

You're assigning the very last element of the msg buffer array to the very last element of the network message array.

You should be copying the string into it.

Share this post


Link to post
Share on other sites
Just in case there is any misunderstanding:

"[128]" is not a part of the name of the array. It is part of the type of the array (i.e., the indication that it is an array, and what its size is). You should not type it when you want to refer to the array itself.

Share this post


Link to post
Share on other sites
Ok let me say it again the problem happens before it has anything to do with that. That doesnt take effect till I hit enter and this issue happens before I hit enter.

Share this post


Link to post
Share on other sites
LittleFreak,

I suspect the problem is not what you think it is. It is very likely the answer has been given to you three or four times by different people, but you've convinced yourself the problem lies elsewhere. Perhaps you're right. Do this for me:

Add a printf or cout statement that outputs the value of m_Chat_Msg just after the line that reads:

"strcat (m_Chat_Msg, m_Chat_Key);"

something like:

"cout << m_Chat_Msg << endl;"

What is the value of m_Chat_Msg? I suspect its the entire string of characters, no? If it is the entire string of characters, the problem is in fact what these good people have told you it is.

If the string is NOT complete, then perhaps we're missing something and you should provide a bit more code so we can see what happens before and after the query.

Also, a debugger is your best friend. Set a breakpoint, look at the value. Then step through the code until the value changes. Being able to use a debugger effectively seperates the wannabes from the true GameDevs.

Share this post


Link to post
Share on other sites
I have one because its a chat system in my game so it prints what your message is how you typed it. And it only displays the last key hit for some reason. Ive been programing awhile so I know that if I got a issue to print varualbes im having issues with at each step of the process but I still dont know why its not working it seems like where I do strcat (m_Chat_Msg, m_Chat_Key); its actully doing strcpy (m_Chat_Msg, m_Chat_Key); But it shouldnt.

Share this post


Link to post
Share on other sites
I think it's just amazing. As technology ensues and we get faster and faster processors and more and more memory ... it seems to meet the demand of imcompetent programming.

I think you need to listen to the above posters and that's kinda ridiculous that you have so many if statements for each possible character... ever heard of a for loop? well i'm sure you have since you say you're such an experienced programmer, heh ya.

Share this post


Link to post
Share on other sites
Those if statements because Im little new to directx and my direct input engine kinda sucks specaily since i wrote it a year ago when i first started with Directx I think im gonna re write it then re write the hole chat program and start fresh.

Share this post


Link to post
Share on other sites
from your code, it's seems like only one letter is going to be in m_chat_msg at any given time. since the if statements are not in a loop of any sort i don't see how you expect a string to form.

maybe more of the code and how you have your arrays initialized would be helpful.

Share this post


Link to post
Share on other sites
Change:
Msg.ChatMsg[128] = m_Chat_Msg[128];
To:
strcpy (Msg.ChatMsg, m_Chat_Msg);

Also where is m_Chat_Msg declared?
If it's LOCAL to the function running this code segemnt, then m_Chat_Msg goes OUT OF SCOPE when you exit out of the function.
Try making m_Chat_Msg GLOBAL or declare it local to you MAIN function.

That should do it. Try it and let us know.

Share this post


Link to post
Share on other sites
i guess i should have mentioned this is just part of my program. It is in a loop and they are all declared in my .h

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement