Game Development Community

getPositionX() and getPositionY no longer available (SceneObject class)?

by Jeff Moretti · in Torque 2D Beginner · 04/14/2014 (6:16 pm) · 8 replies

Hi There,

I noticed that getPositionX() and getPositionY() are no longer available for the SceneObject class. Any chance these will be implemented later?

Thanks,

Jeff

#1
04/14/2014 (6:28 pm)
Why? This works:
%origin = %object.getPosition();
%x = %origin.x;
%y = %origin.y;
#2
04/14/2014 (9:38 pm)
As Richard mentioned, it's not crucial to have separate functions for each but if you want to do it..here's how, it takes literally 1 minute to implement.

ConsoleMethodWithDocs(SceneObject, getPositionX, ConsoleFloat, 2, 2, ())
{
    Vector2 Position = object->getPosition();
    return Position.x;
}

ConsoleMethodWithDocs(SceneObject, getPositionY, ConsoleFloat, 2, 2, ())
{
    Vector2 Position = object->getPosition();
    return Position.y;
}

You can find all SceneObject Console functions in
\Torque2D\engine\source\2d\sceneobject\SceneObject_ScriptBinding.h
#3
04/14/2014 (10:04 pm)
Thanks for beating me to it Simon, was going to post the same thing.

I guess it can't hurt eventually adding those methods to the official codebase. As Richard and Simon sort of mention, it's not a deal breaker but it really comes down to consistency - since we have stuff like getLinearVelocityX or getSizeY, I suppose the position stuff should be added too. The other alternative would be to wipe all those extra methods out and force everyone to use the string accessors, but that might cause an uproar. :)
#4
04/14/2014 (10:26 pm)
@Mike : It's a pleasure to steal your thunder, buddy!

Adding these functions in is trivial and does not "weigh down" the codebase (I think), they simply facilitate user experience. For that reason I say I'm all for including such helper functions wherever they might make sense.

Weird thing, functions setPositionX and setPositionY were already in there so I think that GetPositionX/y were probably lost somewhere along the way.
#5
04/15/2014 (6:33 am)
They were removed when they added the ability to access them the way I described earlier - the new method is very simple and clean. I think I'll look into how they did it and add it to T3D....

Having used both TGB and the newer T2D extensively I can honestly say that I solidly prefer the newer method. Using getWord(%obj.getPosition(), 0) or %obj.getPositionX() both work, but %obj.getPosition().x isn't that far off and actually the .x notation works in many other instances where a space-separated list is returned as well. Really it's only syntactic sugar and they probably shouldn't have removed the old accessor functions, but it is nicer.
#6
04/15/2014 (6:08 pm)
Thanks guys. I didn't know about the .x extension to the getPosition vector. I'll use that one for now.
#7
05/01/2014 (5:33 pm)
%origin = %object.getPosition(); you mentiond this being how we get postion, yet when I try the syntax brings up this error.
NOTE:: I am tryig it on T2DMit

scriptname.cs (124): Unknown command getPosition.
scriptname.cs( 244): Unable to find function getPosition

is the syntax from t2d diffrent from t2dmit. Do I need to add .h files for T2dMit?

#8
05/01/2014 (7:14 pm)
Hi Greyfort

I am not 100% on this, but at first glance, are you sure that %object is a SceneObject? (or %object is a derivative of a SceneObject, like a sprite)?. If %object is just a simobject, then it won't have the getPosition method available to it.

Two things you might want to try:

echo(%object)

- this should give you an id (a number, like 2765, or 2). If it doesn't then that means that %object is undefined

echo(object.dumpClassHierarchy())

- this will output what kind of class(es) that %object belongs too. This will tell you if %object is a SceneObject or not