Game Development Community

isObject giving false positives

by Daniel Buckmaster · in Torque 3D Professional · 11/19/2012 (1:42 am) · 23 replies

I'm using isObject in a script to allow a function to take as an argument an object or a position. Something like:
function AIMoveToAction::onStart(%this, %obj, %data, %resume)
{
   if(isObject(%data))
      %obj.setMoveDestination(%data.getPosition());
   else
      %obj.setMoveDestination(%data);
   error(%data);
   error(isObject(%data));
}
Hilariously, I'm getting console logs that look like this:
2.9938 22.9325 1.28891
0
7.98737 12.3106 1.05857
1
scripts/server/ai/basicActions.cs (44): Unknown command getPosition.
  Object DefaultParticle(7) DefaultParticle -> ParticleData -> SimDataBlock -> SimObject
Um... why is "7.98737 12.3106 1.05857" considered a valid object? That's not right at all. I'll be jumping right onto seeing what's going wrong here, but I just wanted to see if anyone else has already run up against this.

Also, I know that I could just check the word count of the string. The point is, I shouldn't have to. What's happening here is bad!

About the author

Studying mechatronic engineering and computer science at the University of Sydney. Game development is probably my most time-consuming hobby!

Page«First 1 2 Next»
#21
11/20/2012 (12:51 pm)
I'd agree with Dan in this case.
I mean, the function is called 'isObject', which should at least even try to confirm if it's an object to any degree. Filtering incorrect input seems like a sensible tweak to the function.
Obviously, it's possible to get wrong input if you really try, but ensuring it's only an integer or a single word string would take care of *almost* all cases.
#22
11/20/2012 (1:28 pm)
For the record, my changes have nothing to do with spaces in names; they simply ensure that we don't try and cast garbage to an integer handle. On the spaces issue, here's an interesting console session I just had:
==>new ScriptObject(Hello);
3957
==>new ScriptObject(Goodbye);
3958
==>new ScriptObject("hi there");
3959
==>3959.getName();
hi there
==>isObject(Hello);
1
==>isObject(Goodbye);
1
==>isObject("Goodbye Hello");
0
==>isObject("hi there");
1
So that all seems to be working fine.
#23
11/20/2012 (4:05 pm)
Huh, I didn't know it accepted strings with spaces(I figured it may have issues, since that's a weird way to name objects anyways).
So I guess just ensuring that it only accepts integers or strings is the easiest way to filter out most improper usage without breaking anything else.
Page«First 1 2 Next»