Hi fellow wiki editors!

To help newly registered users get more familiar with the wiki (and maybe older users too) there is now a {{Welcome to the wiki}} template. Have a look at it and feel free to add it to new users discussion pages (and perhaps your own).

I have tried to keep the template short, but meaningful. /Johan G

Template:Nasal Class

From FlightGear wiki
Jump to: navigation, search
 # declare a class named myClass
 var myClass = {
    # constructor, for making new objects
  new: func( arg... ) {
   # creates a temporary object that inherits from myClass
   # what is obj here, will later on be 'me' in the actual object
   var obj = { parents:[  myClass   ] };
 
   # do any other object setup here, such as for example
   obj.message = "Hello World";
  
   print("Creating new object/instance of type/template:myClass");    
 
   # return the object to the caller
   return obj;
  },
     # destructor, for deleting objects
   del: func( arg... ) {
   # add your cleanup code here
   print("Deleting object of type/template: myClass");
   return nil;
  },
  
 # declare a method named sayHello
  sayHello: func(name) {
   # do your processing here
   print("Hello ",name); 
  },
   
 # declare a method named setPos
  setPos: func(lat,lon) {
   # do your processing here
   me.lat=lat; me.lon=lon; 
  },
 
 # declare a method named getPos
  getPos: func() {
   # do your processing here
   return [me.lat,me.lon]; 
  },
 };
 
 # now, let's try to create a new object
 var myObject=myClass.new( nil );
 
 
 # call the object's setter method:
 myObject.setPos( lat: 22.00, lon: 66.00 );
 # call the object's getter method to extract the values
 var ( lat,lon ) = myObject.getPos(); 
 
 # you can access all members/fields of the class by using the '''me.''' prefix now
 # add generic example here
 # to delete an object, just call the '''.del()''' method:
 # we will be doing this using a timer, 5 seconds later:
 settimer( func
                myObject.del( nil )
 ,5.00);