Thread: Custom Classes!
View Single Post
  #3  
Old 12-06-2007, 03:18 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by Novo View Post
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.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(typenamesuperclasses) {
  
temp.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 (
iclasses) {
    
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.20;
  
obj.20;
  
obj.32;
  
obj.32;
  if (
obj.contains(player.xplayer.y))
    echo(
"Yep!");
  else
    echo(
"Nope");
  
obj.destroy();

__________________
Reply With Quote