Stringw problem

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
dawasw
Posts: 357
Joined: Tue Aug 10, 2004 4:39 pm
Location: Poland

Stringw problem

Post by dawasw »

In my project I want to set a command by editbox.

Here is what I've tried:

Code: Select all

core::stringw  GetCommand = EditBox->getText();

if(GetCommand==L"hide node"){

q3node->setVisible(false);

}
It doesn't work. Someone can help ?
jam
Posts: 409
Joined: Fri Nov 04, 2005 3:52 am

Post by jam »

instead of

Code: Select all

if(GetCommand==L"hide node")
you might want to try a string compare function like

wcscmp( const wchar_t *string1, const wchar_t *string2)
Conquistador
Posts: 340
Joined: Wed Sep 28, 2005 4:38 pm
Location: Canada, Eh!

Post by Conquistador »

Or:

Code: Select all

if (GetCommand.c_str() == L"hide node")
{
   // Bleh
}
Royal Hamilton Light Infantry - http://www.rhli.ca
Paris/Port Dover Pipes'n Drums - http://www.parisdover.ca
hybrid

Post by hybrid »

Conquistador wrote:Or:

Code: Select all

if (GetCommand.c_str() == L"hide node")
{
   // Bleh
}
No, that would compare pointers which is usually not intended. Convert the constant string to a stringw object and you can use the comparison.
dawasw
Posts: 357
Joined: Tue Aug 10, 2004 4:39 pm
Location: Poland

Post by dawasw »

wcscmp( const wchar_t *string1, const wchar_t *string2)

I have tried above using:

Code: Select all

int result = wcscmp( CommandText=EditBox->getText(), const wchar_t *Command1=L"hide node");

if(result=0){
q3node->setVisible(false);
}

//where result=0 means that strings are the same
But unfortunately it doesn't work.

Hybrid I am not sure what do you mean. Hmm could you point me more of your idea ?

Thanks for help anyway ;)
hybrid

Post by hybrid »

dawasw wrote:Hybrid I am not sure what do you mean. Hmm could you point me more of your idea ?
If you're using pointer to something you shoudl not use "==" but some function which knows how to handle such pointers (e.g. your wcscmp which should work...). But you can also convert the constant string ("hide node") to a stringw object and then compare by using

Code: Select all

GetCommand==NewObject
which would use the stringw method for comparison.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Do this

std::string GetCommand = EditBox->getText().c_str();

if(GetCommand == "hide node")
{

q3node->setVisible(false);

}
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
dawasw
Posts: 357
Joined: Tue Aug 10, 2004 4:39 pm
Location: Poland

Post by dawasw »

@Hybrid

You mean make another stringw and them compare them ? I've tried that but it doesn't work :(

@ Sudi

I have tried your method but I'm receiving this error:

error: request for member `c_str' in `
(*(TextInputBox->irr::gui::IGUIElement::_vptr$IUnknown + 52))(TextInputBox)
', which is of non-aggregate type `const wchar_t*'

----

Any solutions :( ?
jam
Posts: 409
Joined: Fri Nov 04, 2005 3:52 am

Post by jam »

dawasw wrote:wcscmp( const wchar_t *string1, const wchar_t *string2)

I have tried above using:

Code: Select all

if(result=0)
should be

Code: Select all

if(result == 0)
the current way you have it it is always false.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

ups:

std::string GetCommand = stringc(EditBox->getText()).c_str();

if(GetCommand == "hide node")
{

q3node->setVisible(false);

}
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
dawasw
Posts: 357
Joined: Tue Aug 10, 2004 4:39 pm
Location: Poland

Post by dawasw »

Unfortunately that still doesn't work. :(

I've tried all the methods you have adviced me :(

Thanks for help anyway, I really don't know how to solve this.

PS Maybe someone will spend 2 minutes on testing methods above ?
Maybe I have missed something with include, decl. but so far I use <wchar.h> also all irrlicht namespaces are being used.

I use irrlicht 0.12, but I don't think it would do any good in 0.14.
zenaku
Posts: 212
Joined: Tue Jun 07, 2005 11:23 pm

Post by zenaku »

Here's what you want:

Code: Select all

core::stringw  GetCommand = EditBox->getText();

if(wcscmp(GetCommand.c_str(), L"hide node") == 0){

q3node->setVisible(false);

}

dawasw
Posts: 357
Joined: Tue Aug 10, 2004 4:39 pm
Location: Poland

Post by dawasw »

:( Still doesn't work.

I use dev-cpp and irrlicht 0.12 .
zenaku
Posts: 212
Joined: Tue Jun 07, 2005 11:23 pm

Post by zenaku »

dawasw wrote::( Still doesn't work.

I use dev-cpp and irrlicht 0.12 .
Huh? It works for me. Did you #include <wchar.h> ?

Some simple printf's will help you find whats going wrong.

Code: Select all

const wchar_t *text = L"hide node";
core::stringw  GetCommand = EditBox->getText();

// don't forget to use a capital 'S' with printf for wchar_t strings
printf("Command = [%S], comparing to: [%S]\n", GetCommand.c_str(), text);

if(wcscmp(GetCommand.c_str(), text) == 0)
{
    printf("%s\n", "Strings are equal");
    q3node->setVisible(false);
} 
else
{
   printf("%s\n", "Strings are not equal");
 }
dawasw
Posts: 357
Joined: Tue Aug 10, 2004 4:39 pm
Location: Poland

Post by dawasw »

YES ! YES ! YES !

Great thanks Zenaku !

Thanks to printf I was avaible to see what is wrong, now everything works properly.

It was just a 'space' after I was writing a command in EditBox and hitting Enter to enter command into console.

Thanks a lot again ! :D

Here I will show how it work, I made a very simple console for my Quentin FPS game project:

Image


Image


I made it very simple, I recompiled Irrlicht with Acki's dev-cpp recompiler and his extensions included in it (with based on Dark Rain's code chatbox).

At first I made a bitmap, then I made a chatbox with editbox. I used a boolean for setVisible(true) and setVisible(false) for console elements.
To use tilde key for it I just declared tilde key with hex value.

And now I can use some commands finally ;)

I just wrote how I made such console, because maybe some amateur & novice users like me would like to also have such thing in their projects.

Thanks to all again !
Post Reply