Some programming issues

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.
Post Reply
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Some programming issues

Post by sudi »

Ok first of all i probably would never bother anyone of u with stuff like this but this is really driving me crazy!!!
Its just 5 lines of code and it doesn't work. Please take a look.

Code: Select all

void load(char* RigType)
{
     int collision = 0;
     char* rigging = RigType;
     printf("The Rigging Type for this entity is %s\n",rigging);
     
     if(rigging == "box")
     {
                printf("Building Box Body\n");
                collision = 1;
     }
     if(rigging == "sphere")
     {
                printf("Building Sphere Body\n");
                collision = 2;
     }
     if( collision == 0)
     {
         printf("Building Box Body because no RigType was set\n");
         collision = 1;
     }
}
and when i then call it with like:

Code: Select all

std::string rig = "sphere";
load((char*)rig.c_str());
it always prints out Building Box Body because no RigType was set
but it always does it no matter what i set the rig string. anybody any ideas?
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.
jrm
Posts: 111
Joined: Tue Dec 13, 2005 8:57 pm

Post by jrm »

What does the:
printf("The Rigging Type for this entity is %s\n",rigging);
Have in it?

Also I think, I am not 100% sure, but I think chars use single quotes when doing a conditional statment. If (var =='test')...

Thank you,

Josh
vickylh
Posts: 9
Joined: Thu Mar 09, 2006 4:43 pm

try

Post by vickylh »

try strcmp(char *s1,char * s2);
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Your string comparisons aren't going to work like you expect. Try

Code: Select all

  if (!strcmp(RigType, "box")) // use stricmp if you don't care about case
vickylh
Posts: 9
Joined: Thu Mar 09, 2006 4:43 pm

WOW

Post by vickylh »

vitek wrote:Your string comparisons aren't going to work like you expect.

Code: Select all

  char* rigging = RigType;
  if (rigging == "box")
In the above code, you are comparing two pointers. The pointer that the user passed in, and the pointer to the string "box". Unless you managed to find a way to point riggint to the exact same memory address as "box", it won't work. You need to do this instead...

Code: Select all

  if (!strcmp(RigType, "box")) // use stricmp if you don't care about case
WOW!it's that!
jrm
Posts: 111
Joined: Tue Dec 13, 2005 8:57 pm

Post by jrm »

Yeah that is right. That is why other classes, types, have a compare function.

Thank you for the clarification, forgot about the pointer stuff.

Thank you,

JRM
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Oh thanks u just saved me a lot of time i totaly forgot about that....


@jrm
printf("The Rigging Type for this entity is %s\n",rigging);

will print The Rigging Type for this entity is in the win32 console and the string saved in rigging at the pos of %s.
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.
vickylh
Posts: 9
Joined: Thu Mar 09, 2006 4:43 pm

load false

Post by vickylh »

i downloaded your Projects,but when i used the server,it told me that the map loaded false.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Then u tiped in a wrong map name. but i stoped devolping it. u can have the source when u want to develop it further.
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.
Post Reply