Extending Array Library on inline Interface Property

Hello, I have a defined interface here:
export interface SlotData {
loginTimes: number;
ownedGamepasses: Array<string>;
firstLoad: boolean;
money: number;
lastSaved: number;
gems: number;
rebirths: number;
objects: ObjectData[];
NPCs: NPCData[];
vehicles: VehicleData[];
captures: Array<string>;
ownedDLC: Array<string>;
achievements: Array<string>;
researches: ResearchData[];
}
export interface SlotData {
loginTimes: number;
ownedGamepasses: Array<string>;
firstLoad: boolean;
money: number;
lastSaved: number;
gems: number;
rebirths: number;
objects: ObjectData[];
NPCs: NPCData[];
vehicles: VehicleData[];
captures: Array<string>;
ownedDLC: Array<string>;
achievements: Array<string>;
researches: ResearchData[];
}
I'd like to look at this line here objects: ObjectData[]; The definition for ObjectData is below:
export interface ObjectData {
id: number;
ref: string;
pos: {
x: number;
y: number;
z: number;
};
rot: {
x: number;
y: number;
z: number;
};
}
export interface ObjectData {
id: number;
ref: string;
pos: {
x: number;
y: number;
z: number;
};
rot: {
x: number;
y: number;
z: number;
};
}
I would like to access ObjectData of a slot and use Array functions on it such as splice, however when I attempt to do so I get can error, I've attached it. The goal is to remove the particular ObjectData interface from the ObjectData[] array. If it is helpful, I have included my addobject method:
public addObject(object: ObjectData): boolean {
if (this.data && this.data.slots[this.slot]) {
this.data.slots[this.slot].objects[object.id] = object;
return true;
}
return false;
}
public addObject(object: ObjectData): boolean {
if (this.data && this.data.slots[this.slot]) {
this.data.slots[this.slot].objects[object.id] = object;
return true;
}
return false;
}
Thanks!
No description
1 Reply
Braden
BradenOP3y ago
is there a way to remove a value in an array by its key in typescript yeah I think I found it its .remove wait nope hmm i don't care about the order of items, but for performance I'd like to be able to index each object by its ID the IDs start at 0 and go all the way up. If an object is removed, I want to make the id available for a different object maybe I need to rethink the array... Right thanks! ill try this out this is user data, so I would like the most stable option. Objects: [number, number, number, number, number, number, number, number, OldExtraObjectData][]; so this would change to map oh, yeah i dont want accidental bugs lol oh I see ah just for organization, yeah and for maps you do need to call .set? how do I set an empty map, im new to typescript so I appreciate your help objects: [], this is for seting up the default userdata, ofc it needs to change because I've changed to maps thanks! also, what is Roblox TS's to number function for converting string to number thanks!

Did you find this page helpful?