<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://www.solarstrike.net/wiki/index.php?action=history&amp;feed=atom&amp;title=Classes</id>
		<title>Classes - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://www.solarstrike.net/wiki/index.php?action=history&amp;feed=atom&amp;title=Classes"/>
		<link rel="alternate" type="text/html" href="https://www.solarstrike.net/wiki/index.php?title=Classes&amp;action=history"/>
		<updated>2026-06-17T16:03:04Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>https://www.solarstrike.net/wiki/index.php?title=Classes&amp;diff=1152&amp;oldid=prev</id>
		<title>Elverion: Protected &quot;Classes&quot; ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite))</title>
		<link rel="alternate" type="text/html" href="https://www.solarstrike.net/wiki/index.php?title=Classes&amp;diff=1152&amp;oldid=prev"/>
				<updated>2014-07-02T21:11:23Z</updated>
		
		<summary type="html">&lt;p&gt;Protected &amp;quot;&lt;a href=&quot;/wiki/index.php/Classes&quot; title=&quot;Classes&quot;&gt;Classes&lt;/a&gt;&amp;quot; ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite))&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 21:11, 2 July 2014&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Elverion</name></author>	</entry>

	<entry>
		<id>https://www.solarstrike.net/wiki/index.php?title=Classes&amp;diff=1151&amp;oldid=prev</id>
		<title>Elverion: Created page with &quot;==What are classes?==  Classes are simply a way to organize data to reflect an object. For example, you might have a player class that represents the player's object in the ga...&quot;</title>
		<link rel="alternate" type="text/html" href="https://www.solarstrike.net/wiki/index.php?title=Classes&amp;diff=1151&amp;oldid=prev"/>
				<updated>2014-07-02T21:10:19Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;==What are classes?==  Classes are simply a way to organize data to reflect an object. For example, you might have a player class that represents the player&amp;#039;s object in the ga...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==What are classes?==&lt;br /&gt;
&lt;br /&gt;
Classes are simply a way to organize data to reflect an object. For example, you might have a player class that represents the player's object in the game world. That class would contain things such as health, position, status, and whatever else you can think of.&lt;br /&gt;
&lt;br /&gt;
Classes can also use inheritance. Inheritance means that one object shares certain functionality with its &amp;quot;parent.&amp;quot; If you were to make an object to represent a cat or dog, you might inherit behavior from the animal class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Creating a new class==&lt;br /&gt;
To create a new class, all you need to do is call [[Class_Module#new|class.new]](). Calling that function with no parameters will return an empty class and will not call its constructor. If you call class.new() and pass it an object, it will return a new class that inherits behavior from that object.&lt;br /&gt;
&lt;br /&gt;
''Example:''&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
Animal = class.new(); -- Make a new class, lets call it animal.&lt;br /&gt;
&lt;br /&gt;
Cat = class.new(Animal); -- Make a new class called cat, which is a subclass of animal&lt;br /&gt;
Dog = class.new(Animal); -- Dogs are also a different subclass of animal, and may have different attributes than cats&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Instantiation==&lt;br /&gt;
Declaring a new class does ''not'' give immediately give you an object that you should use directly. Instead, think of it like a recipe: it tells you what the object contains, but it isn't ready to use.&lt;br /&gt;
&lt;br /&gt;
In order to actually create an instance of a class, you need only to call its baseclass as a function, like so:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
fluffy = Dog(); -- fluffy is now an object of type Dog&lt;br /&gt;
lucky = Dog(); -- lucky can be a different Dog&lt;br /&gt;
stripes = Cat(); -- And stripes can be a Cat&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Constructors==&lt;br /&gt;
Constructors are the functions that get called when creating an instance of a class. If we wanted our Dog to bark when we create one, we could do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function Dog:constructor()&lt;br /&gt;
    print(&amp;quot;Bark!&amp;quot;);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fluffy = Dog(); -- This should now print &amp;quot;Bark!&amp;quot; on the screen.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A constructor can also take arguments. If, for some strange reason, you wanted to pass in the dog's age when creating it, you can do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function Dog:constructor(age)&lt;br /&gt;
    print(&amp;quot;Bark! I am age &amp;quot;, age);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
fluffy = Dog(5); -- Should print: Bark! I am age 5&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You may also wish to call its parent's constructor. You must be careful here. Do ''not'' call self.parent:constructor() directly, as doing so may cause an infinite loop and possibly a stack overflow. The proper way to do it is to specify the parent by calling &amp;lt;classname&amp;gt;.parent.constructor(self) instead.&lt;br /&gt;
&lt;br /&gt;
Before Dog constructs itself, it might want to first initiate itself with some data:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function Animal:constructor()&lt;br /&gt;
    self.type = &amp;quot;Animal&amp;quot;;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function Dog:constructor()&lt;br /&gt;
    Dog.parent.constructor(self);&lt;br /&gt;
    print(self.type);  -- This should print &amp;quot;Animal&amp;quot;;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Variables &amp;amp; Functions==&lt;br /&gt;
A class can contain any number of variables. It is recommended that class variables are declared in its constructor for clarity and for inheritance reasons. When calling from inside of a class, variables and functions, should be preceeded by &amp;quot;self.&amp;quot; and when called from outside you should use &amp;quot;.&amp;quot; to access variables or &amp;quot;:&amp;quot; to call functions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Create our baseclass&lt;br /&gt;
Animal = class.new();&lt;br /&gt;
function Animal:constructor()&lt;br /&gt;
    self.text = &amp;quot;Unknown animal noise&amp;quot;;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function Animal:speak()&lt;br /&gt;
    print(self.text);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-- Create a dog, override self.text to bark.&lt;br /&gt;
Dog = class.new(Animal);&lt;br /&gt;
function Dog:constructor()&lt;br /&gt;
    Dog.parent.constructor(self);&lt;br /&gt;
    self.text = &amp;quot;Bark!&amp;quot;;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Create a cat, override self.text to meow.&lt;br /&gt;
Cat = class.new(Animal);&lt;br /&gt;
function Cat:constructor()&lt;br /&gt;
    Cat.parent.constructor(self);&lt;br /&gt;
    self.text = &amp;quot;Meow!&amp;quot;;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-- Now lets see what happens when we make them speak!&lt;br /&gt;
cat = Cat();&lt;br /&gt;
cat:speak(); -- The cat should meow&lt;br /&gt;
&lt;br /&gt;
dog = Dog();&lt;br /&gt;
dog:speak(); -- And the dog should bark&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Destructors &amp;amp; Other Metatable Magic==&lt;br /&gt;
You may override a class's metatable in order to change its behavior. You might want to override __gc to be a destructor: a function that is called when the object is deleted. You may also want to allow the object to be used with operators such as __add (+), or __sub (-). In order to do this, you'll need to modify the metatable associated with that operation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
getmetatable(Cat).__gc = function ()&lt;br /&gt;
    print(&amp;quot;The cat has died :(&amp;quot;);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
cat = Cat(); -- Make a new cat, it should meow.&lt;br /&gt;
cat = nil; -- Now the cat has dies... so sad. The deconstructor should automatically be called now.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Elverion</name></author>	</entry>

	</feed>