Game Development Community

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:

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?

#1
01/16/2013 (4:41 am)
In TorqueScript you have 2 types, ints and strings.
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.
#2
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.