String comparison form datablock
by Marcus L · in Torque 3D Professional · 04/28/2010 (8:49 am) · 10 replies
"String comparison form datablock" how to do this? For example i have a variable defined in my datablock, decalType = "explosive";, and i want to do a string comparison with this variable in c++. Now, can anybody tell me why the following code won't work in my case:
Thanks in advance!
if(mDataBlock->decalType == "explosive") doSomething();
Thanks in advance!
#2
note: this code will still not work
04/28/2010 (10:59 pm)
Like this you mean?//projectile.h StringTableEntry decalType; ... //projectile.cpp @ ProjectileData::ProjectileData() decalType = NULL; ... //projectile.cpp @ ProjectileData::initPersistFields() addNamedField(decalType, TypeCaseString, ProjectileData);
note: this code will still not work
#4
nobbish question commencing
How to? I mean how do i debug a variable using break points.
I will keep on debugging.
Thanks for your replies.
EDIT: The code i tried
EDIT2: One more thing. In my datablock i defined...
EDIT3: Seems my decalType variable returns a long string of numbers(131295012) if output to the console via Con::printf. Why?
04/29/2010 (6:11 am)
I tried your dStricmp, but same result. No i do not get an error message, i believe it always returns false.Quote:Try putting in a break point and make a debug build and look at the value of mDataBlock->decalType
nobbish question commencing
How to? I mean how do i debug a variable using break points.
I will keep on debugging.
Thanks for your replies.
EDIT: The code i tried
if(dStricmp(mDataBlock->decalType, "explosive"))
{
gDecalManager->addDecal( p, n, 0.0f, m->mExplosiveDecal );
//Plus an Con::printf here for debugging purposes
}EDIT2: One more thing. In my datablock i defined...
decalType = "explosive";... is that right?
EDIT3: Seems my decalType variable returns a long string of numbers(131295012) if output to the console via Con::printf. Why?
#6
EDIT: Figured the problem, somehow.
04/29/2010 (12:29 pm)
Thanks for the help, but, changing to "debug" will just give me a bunch of linker errors =/. So I'll just continue debugging from "release" build. Thanks for the help tho!EDIT: Figured the problem, somehow.
#7
May return what you want... or you may need to do a object->getDataBlock() first if the field is on the object datablock instead of the object itself.
04/30/2010 (7:10 am)
Actually, you can access script members variables from C++, tryobject->getDataField("decalType","");May return what you want... or you may need to do a object->getDataBlock() first if the field is on the object datablock instead of the object itself.
#8
04/30/2010 (9:17 am)
Ok, so now it works, kinda. It seems that doing dStricmp crashes the engine, and using an == operator does not work. Anyone has an explanation why putting an if statement comparing two strings in Projectile::explode crashes, and the workaround?
#10
But thanks for the help and tips about debugging and string comparing.
05/02/2010 (6:22 am)
Just figured the problem is not related to string comparing or anything like that. The problem is related to some custom code that are getting the material of the object my projectile is colliding with.But thanks for the help and tips about debugging and string comparing.
Torque 3D Owner Sean H.