Quote:
Originally Posted by Novo
Yea... I was talking with Stan, and I was like 'you can't make custom classes using the new operator'
|
The new operator can be used with an object name or the name of an object type, and when used with an existing object it copies all variables to the new object including this.joinedclasses, causing the classes in the copied object to be joined to the new object.
PHP Code:
public function onCreated() {
temp.i = 0;
this.scriptlogmissingfunctions = false;
this.types = null;
// MudObjects
maketype("MudObject", null, {"util_triggerall", "util_schedulefunction", "type_mudobject"});
maketype("MudPlayer", TMudObject, {"type_mudplayer"});
maketype("MudItem", null, {"util_schedulefunction", "type_muditem"});
// Dialog
maketype("DialogTopic", null, {"type_dialogtopic"});
maketype("DialogResponse", null, {"type_dialogresponse"});
maketype("DialogCondition", null, {"type_dialogcondition"});
// Misc
maketype("IniFile", null, {"type_inifile"});
maketype("DataFile", null, {"type_datafile"});
maketype("Rectangle", null, {"type_rectangle"});
this.created = true;
}
public function maketype(typename, super, classes) {
temp.i = 0;
if (makevar("T"@typename) != null) {
makevar("T"@typename).destroy();
}
this.(@ "type_" @ typename) = new TStaticVar("T"@typename);
if (super.type() == 2) {
this.(@ "type_" @ typename).joinedclasses = super.joinedclasses;
}
for (i: classes) {
this.(@ "type_" @ typename).join(i);
}
if (this.types.index("T"@typename) < 0) {
this.types.add("T"@typename);
}
}
PHP Code:
// Use
function onCreated() {
temp.obj = 0;
obj = new TIniFile();
obj.load("data/news.ini");
// More Stuff
obj.destroy();
obj = new TRectangle();
obj.x = 20;
obj.y = 20;
obj.w = 32;
obj.h = 32;
if (obj.contains(player.x, player.y))
echo("Yep!");
else
echo("Nope");
obj.destroy();
}