Property 'length' does not exist on type 'Vector3[]'

So I'm making a module script in vscode, the problem originates in my renderBelt() function
11 Replies
longuint
longuintOP2y ago
import { Workspace } from "@rbxts/services";
import { calculatePos } from "./Modules/Spline";

/**
* @name ConveyorPole
* @description Connects to a Conveyor.
*/
export class ConveyorPole {
public position: CFrame;
public connectedBelts: Conveyor[] | undefined;

constructor(position: CFrame, connectedBelts?: Conveyor[]) {
this.position = position;
this.connectedBelts = connectedBelts;
}
}
/**
* @name Conveyor
* @description The physical belt between two or more ConveyorPoles.
*/
export class Conveyor {
public conveyorPoles: ConveyorPole[];

constructor(conveyorPoles: ConveyorPole[]) {
this.conveyorPoles = conveyorPoles;
}

renderBelt() {
const newPoints: Vector3[] = [];
this.conveyorPoles.forEach((point: ConveyorPole) => {
newPoints.push(new Vector3(point.position.X, point.position.Y, point.position.Z));
});

for (let i = 0; i < newPoints.length - 1; i++) {}
//!TODO Render the belt using Mesh Deformations instead.
// const Part = new Instance("Part");
// Part.Size = new Vector3(2, 0.5, 1);
// Part.Anchored = true;

}
}
import { Workspace } from "@rbxts/services";
import { calculatePos } from "./Modules/Spline";

/**
* @name ConveyorPole
* @description Connects to a Conveyor.
*/
export class ConveyorPole {
public position: CFrame;
public connectedBelts: Conveyor[] | undefined;

constructor(position: CFrame, connectedBelts?: Conveyor[]) {
this.position = position;
this.connectedBelts = connectedBelts;
}
}
/**
* @name Conveyor
* @description The physical belt between two or more ConveyorPoles.
*/
export class Conveyor {
public conveyorPoles: ConveyorPole[];

constructor(conveyorPoles: ConveyorPole[]) {
this.conveyorPoles = conveyorPoles;
}

renderBelt() {
const newPoints: Vector3[] = [];
this.conveyorPoles.forEach((point: ConveyorPole) => {
newPoints.push(new Vector3(point.position.X, point.position.Y, point.position.Z));
});

for (let i = 0; i < newPoints.length - 1; i++) {}
//!TODO Render the belt using Mesh Deformations instead.
// const Part = new Instance("Part");
// Part.Size = new Vector3(2, 0.5, 1);
// Part.Anchored = true;

}
}
PepeElToro41
PepeElToro412y ago
for arrays, the way to get the size is with arr.size(), not length little different from js
longuint
longuintOP2y ago
I see, thank you. Could this also be done with newPoints.forEach((point: ConveyorPole) => {});?
PepeElToro41
PepeElToro412y ago
wym
longuint
longuintOP2y ago
newPoints.forEach((point: ConveyorPole) => {})
PepeElToro41
PepeElToro412y ago
yeah you can do that if you dont wanna use loops, you can also do for(const point of newPoints){}, the only problem is that you cant get the index of it
longuint
longuintOP2y ago
can't you just use the 2nd optional param of forEach like (point, _index)?
PepeElToro41
PepeElToro412y ago
yes, I meant the "for" way
longuint
longuintOP2y ago
Right Alright, thanks for the help.
PepeElToro41
PepeElToro412y ago
no problem
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?