Home » Renegade Discussions » Mod Forum » weird reaction with const w_chart
Re: weird reaction with const w_chart [message #464063 is a reply to message #464060] |
Fri, 09 March 2012 06:53 |
iRANian
Messages: 4308 Registered: April 2011
Karma:
|
General (4 Stars) |
|
|
You're using %s with a wchar_t in formatted functions, you need to use %S. Casting a char to wchar_t (if it works) can cause memory corruption. Instead of using wchar_t, use StringClass. Instead of using Console_Input, use a wrapper function that takes formated input like Console_Output() does. This is how I would write the code:
Toggle Spoiler// Console_Input() taking formatted input
void Console(const char *Format, ...)
{
char buffer[256];
va_list va;
_crt_va_start(va, Format);
vsnprintf(buffer, 256, Format, va);
va_end(va);
Console_Input(buffer);
}
// Call Kambot_Commands() via chat
bool Kambot::OnChat(int PlayerID,TextMessageEnum Type,const wchar_t *Message,int recieverID)
{
StringClass Msg = Message;
Kambot_Commands(PlayerID, Type, Msg, recieverID);
return true;
}
void Kambot_Commands(int PlayerID,TextMessageEnum Type, StringClass Msg,int recieverID)
{
Console("MSG Debug: Kambot_Commands() called"); // DEBUG CRAP
Console("MSG Debug: Kambot_Commands() MSG == %s", Msg); // DEBUG CRAP
if (Msg[0] == '!')
{
Console("MSG Debug: Kambot_Commands() Command triggered"); // DEBUG CRAP
}
}
// Call Kambot_Commands() via a Keyhook (using keys.cfg keys)
void KB_keyhook::KeyHook()
{
if((The_Game()->Get_Game_Duration_S() - LastPress) >= 1)
{
StringClass Msg = Get_Parameter("Command");
Kambot_Commands(Get_Player_ID(Owner()), TEXT_MESSAGE_TEAM, Msg, -1); // Last parameter isn't used
Console("MSG Debug: KeyHook() called with %s", Msg); // DEBUG CRAP
LastPress = The_Game()->Get_Game_Duration_S();
}
}
Not sure if it actually runs correctly though, didn't bother checking. You can also use the __FUNCTION__ and __LINE__ macros to grab the function the code is executing and the line number while debugging.
Long time and well respected Renegade community member, programmer, modder and tester.
Scripts 4.0 private beta tester since May 2011.
My Renegade server plugins releases
|
|
|
|
|
weird reaction with const w_chart
By: robbyke on Fri, 09 March 2012 06:21
|
|
|
Re: weird reaction with const w_chart
By: iRANian on Fri, 09 March 2012 06:53
|
|
|
Re: weird reaction with const w_chart
By: robbyke on Fri, 09 March 2012 10:51
|
|
|
Re: weird reaction with const w_chart
By: iRANian on Sat, 10 March 2012 17:05
|
|
|
Re: weird reaction with const w_chart
By: Ethenal on Sat, 10 March 2012 18:28
|
|
|
Re: weird reaction with const w_chart
By: iRANian on Sun, 11 March 2012 05:19
|
|
|
Re: weird reaction with const w_chart
By: robbyke on Sun, 11 March 2012 06:54
|
|
|
Re: weird reaction with const w_chart
By: iRANian on Sun, 11 March 2012 07:50
|
|
|
Re: weird reaction with const w_chart
By: jonwil on Sun, 11 March 2012 08:32
|
|
|
Re: weird reaction with const w_chart
By: robbyke on Sun, 11 March 2012 08:34
|
|
|
Re: weird reaction with const w_chart
By: iRANian on Sun, 11 March 2012 09:03
|
|
|
Re: weird reaction with const w_chart
By: jonwil on Sun, 11 March 2012 08:45
|
|
|
Re: weird reaction with const w_chart
By: iRANian on Sun, 11 March 2012 09:07
|
|
|
Re: weird reaction with const w_chart
By: robbyke on Sun, 11 March 2012 14:04
|
|
|
Re: weird reaction with const w_chart
By: jonwil on Sun, 11 March 2012 19:18
|
|
|
Re: weird reaction with const w_chart
|
|
|
Re: weird reaction with const w_chart
By: iRANian on Mon, 12 March 2012 11:28
|
Goto Forum:
Current Time: Wed Dec 18 19:41:29 MST 2024
Total time taken to generate the page: 0.00807 seconds
|