Direct refrence to member variable fail

Started by EK.IceFlake, Feb 14, 2015, 05:27 AM

Previous topic - Next topic

EK.IceFlake

Hi guys! I was making a script for my squirrel API, but it didnt allow a direct refrence
function Vector::ForwardPoint(distance, angle) return Vector(x + 1.0 * cos(angle * 3.14159265359 / 180.0) - 25.0 * sin(rad), y + 1.0 * sin(angle * 3.14159265359 / 180.0) + 25.0 * cos(rad), z);it prints Member variable not found
Vector(1, 2, 3).x works very fine...

.

Shouldn't those be this.x, this.y, this.z ? And also prefixed with :: like ::cos(), ::sin() etc. But I'm not sure what you're trying to achieve here.
.

EK.IceFlake

#2
Quote from: S.L.C on Feb 14, 2015, 05:34 AMShouldn't those be this.x, this.y, this.z ? And also prefixed with :: like ::cos(), ::sin() etc. But I'm not sure what you're trying to achieve here.
Function that returns a pos in front of a vehicle

Not works
function Vector::ForwardPoint(distance, angle) return Vector(this.x + 1.0 * ::cos(angle * 3.14159265359 / 180.0) - 25.0 * ::sin(rad), this.y + 1.0 * ::sin(angle * 3.14159265359 / 180.0) + 25.0 * ::cos(rad), this.z);

Gudio

#3
- 'rad' variable isn't declared and you try to use it anyway,
- 'distance' is not never used,
- function Vector::ForwardPoint will not work in this case.

Solutions:
- declare 'rad' variable that will convert degrees to radians,
- remove 'distance' variable or try to use while calculating position,
- function getForwardPoint(vector, rad, distance) would be better.