[SOLVED] Confused about OOP

I have method like this which works weirdly
addItem(Item: new (...args: never[]) => Item) {
if (this.item === undefined) {
this.item = new Item();
print(Item);
print(this.item);
print("Item Added into the slot!");
}
}
addItem(Item: new (...args: never[]) => Item) {
if (this.item === undefined) {
this.item = new Item();
print(Item);
print(this.item);
print("Item Added into the slot!");
}
}
1st print prints Class name, that's correct 2nd print for some reason prints just empty table which is really weird the class in question:
export class Box extends Item {
constructor() {
if (ItemsFolder && ItemsFolder.IsA("Folder")) {
const model = ItemsFolder.FindFirstChild("Box");
if (model && model.IsA("Model")) {
super("Box", model, "Very cool box!");
this.id = 2;
}
}
}

use(): void {
print("dumbass, box has no use");
}
}
export class Box extends Item {
constructor() {
if (ItemsFolder && ItemsFolder.IsA("Folder")) {
const model = ItemsFolder.FindFirstChild("Box");
if (model && model.IsA("Model")) {
super("Box", model, "Very cool box!");
this.id = 2;
}
}
}

use(): void {
print("dumbass, box has no use");
}
}
25 Replies
Nightmare
NightmareOP2w ago
also sorry that I am asking for so much questions last two weeks, I am learning it and just, way too many errors
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Nightmare
NightmareOP2w ago
exactly
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Nightmare
NightmareOP2w ago
yes
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Nightmare
NightmareOP2w ago
but like that print return name of that class which is completly correct yes, just it can be any other class(Box is there for testing rn) any other class inheret from class Item*
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Nightmare
NightmareOP2w ago
it should this is Item class
export class Item {
public id: number;
private name: string;
private model: Model;
private description?: string;

constructor(name: string, model: Model, description: string) {
this.id = 1;
this.name = name;
this.model = model;
this.description = description;
}
use(): void {
print(`${this.name} used!`);
}

getInfo() {
return {
id: this.id,
name: this.name,
description: this.description,
model: this.model,
};
}
}
export class Item {
public id: number;
private name: string;
private model: Model;
private description?: string;

constructor(name: string, model: Model, description: string) {
this.id = 1;
this.name = name;
this.model = model;
this.description = description;
}
use(): void {
print(`${this.name} used!`);
}

getInfo() {
return {
id: this.id,
name: this.name,
description: this.description,
model: this.model,
};
}
}
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Nightmare
NightmareOP2w ago
18:38:46.115 ▼ {
["description"] = "Hi!",
["id"] = 1,
["model"] = Model,
["name"] = "something"
} - Server - inventory-service:161
18:38:46.115 ▼ {
["description"] = "Hi!",
["id"] = 1,
["model"] = Model,
["name"] = "something"
} - Server - inventory-service:161
works completly fine
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Nightmare
NightmareOP2w ago
to be honest, I have no idea I will probably remake it from scratch but I still need to know the core of this issue lol wait oh the issue will probably be "Box" class but idk why
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Nightmare
NightmareOP2w ago
oh i maybe found out the issue yup how there is an if statement for finding that folder I kind of gave it a wrong name now it looks like it works? yeah it does, new errors xd
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Nightmare
NightmareOP2w ago
uh I think we found limits of my knowledge what does abstract class means
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Nightmare
NightmareOP2w ago
yeah that's what I did? or i did not?
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Nightmare
NightmareOP2w ago
oh, yeah, idk why but i though it would be cool to like make it possible to create custom item in game so i kept it like this uh i guess i create it with some keyword right?
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Nightmare
NightmareOP2w ago
oh lol thanks
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Nightmare
NightmareOP2w ago
oh okey cool

Did you find this page helpful?