Comparing vectors... [Solved]
by Max Kielland · in Torque Game Builder · 01/16/2013 (12:19 am) · 2 replies
Hi,
A vector is written like "1.0 2.0" but how do I compare two vectors?
For example:
What is the proper/intended way to compare vectors?
A vector is written like "1.0 2.0" but how do I compare two vectors?
For example:
if(%this.getLinearVelocity == "0.0 0.0") // generates compile error if(%this.getLinearVelocity $= "0.000000 0.000000") // Works but doesn't feel to good
What is the proper/intended way to compare vectors?
About the author
Owner of MK Development www.mkdevelopment.se
#2
I was thinking that maybe the vector string was converted into two floats and then compared, float by float.
I did found the t2dVectorCompare() in the TDN after some extensive searching. tdn.garagegames.com/wiki/TGB/Reference:_Vector_Manipulation_Functions#t2dVectorC...
This function seems to compare two vectors within a margin of error.
01/16/2013 (5:17 am)
Okay, this confirms what I suspected.I was thinking that maybe the vector string was converted into two floats and then compared, float by float.
I did found the t2dVectorCompare() in the TDN after some extensive searching. tdn.garagegames.com/wiki/TGB/Reference:_Vector_Manipulation_Functions#t2dVectorC...
This function seems to compare two vectors within a margin of error.
Torque Owner Lukas Joergensen
WinterLeaf Entertainment
When you compare with == you compare two integers when you compare $= you compare two strings.
As a vector can't be said to be a single number, comparing as a string is the correct way.
Classes, and objects are in TorqueScript represented as strings, usually an ID but as the Point2F class doesn't have an ID, they are parsed to strings as they go from engine to script, and parsed from strings when they go from script to engine, and thats why you would have to compare it as a string.