I have another small problem.
For my game I'm using gamemonkey as an embedded scripting language so I don't have to hardcode everything in C++. Now in C++, i have a function called void CharacterSay(irr::core::stringw) that is bound to a script function called CharacterText(text).
Now the gamemonkey's engine returns text as char *, but Irrlicht works with wchar_t *. So when I say in my script file:
CharacterText("welcome to my game");
It sends that text to the bound function to display in a dialog box(like those found in Japanese RPGs).
Now when I run the program, due to improper conversion of the char* to wchar_t *, instead of my text, I get boxes instead of letters.
If I test the function hardcoded inside C++ I get my text, since in C++ I have to enter it as a wchar_t.
Please how do I convert from char* to wchar_t * properly so I get my letters and numbers.
Conversion from wchar_t to char
Search the forum, many times asked and answered...
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:

http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
After googling wchar_t, it is a datatype capable of storing all characters in all languages that might be supported. It seems to have been adapted to storing UNICODE representations of data as either 16 or 32 bit characters.
So long as all of your strings fall within the original ASCII 7 character set you can perform a simple conversion, copying the wide characters to traditional C characters. A C string is an array of characters terminating in a null character (a zero).
For any string w with a non-zero length this should work:
This function will break if any of the characters are greater than 255 (which covers up to Latin-1 extensions as I recall), or if the string w is not a valid string (if w does not contain a null end of string this function will overwrite variables after the end of c...presumably you will have already checked to see that w contains a valid string before calling this function.
Let me know if this helps!
-Jay
So long as all of your strings fall within the original ASCII 7 character set you can perform a simple conversion, copying the wide characters to traditional C characters. A C string is an array of characters terminating in a null character (a zero).
For any string w with a non-zero length this should work:
Code: Select all
void WCharToChar(char* c, wchar_t* w)
{
int i=0;
if (w[i])
for (i=0; w[i]; i++)
c[i] = (char)w[i];
c[i] = 0;
}Let me know if this helps!
-Jay
Last edited by datamagik on Thu Feb 22, 2007 10:39 pm, edited 1 time in total.
Right, why doing it simple if there also is a hard way (like this function)... 
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:

http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Although it was easier for me to just jot down that conversion function than comb through all the entries that come up in search
I realized our friend must know of something in the engine which would be more reliable.
Sure enough, the conversion routine is already available to us and was described in this earlier posting which I found by searching for "wchar_t"
http://irrlicht.sourceforge.net/phpBB2/ ... ght=wchart
Sure enough, the conversion routine is already available to us and was described in this earlier posting which I found by searching for "wchar_t"
http://irrlicht.sourceforge.net/phpBB2/ ... ght=wchart
Well, I didn't want this, but alright... 
You're reinventing the wheel !!!
Use this:
You're reinventing the wheel !!!
Use this:
Code: Select all
// convert from char* to wchar_t*
mbstowcs(wchar_t*, const char*, size_t);
// convert from wchar_t* to char*
wcstombs(char*, const wchar_t*, size_t);while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:

http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java