View Single Post
Old 01-27-2012, 09:59 PM   #78
Master of Puppets
VarsityPuppet's Avatar
Join Date: May 2009
Location: MN
Posts: 1,289
Current Game: Chrono Trigger
Contest winner - Modding  Forum Veteran  Veteran Modder  Helpful! 
But what is a method exactly?

To put it simply, it's a way of simplifying and organizing your code by segmenting it into different parts.

All of the same syntax applies, it's just WAAAY easier to read in some cases.

Let's say we have an object that we want to do a series of commands. Let's say we want a Jedi to Force shock a Sith.

That script might look like this:
Show spoiler

Fair enough, but what if we want the Jedi to use more than one spell in a sequence? That would look something like this:
Show spoiler

Fair enough again, but what if we have another Jedi join in on the Sith torture? Would we have to keep adding AssignCommand calls? No, not necessarily. Check out the following code:

Show spoiler

For every instance of torture in void main, it will actually read the code in void torture(), substituting the parameters for whichever objects you write in! Cool huh?

Now, not ever method has to be void main() or void whatever(), you can actually write something like:

int countMyFoes()
string getMyName()
object getWeakestEnemy()

but that's a lesson for another time...

VarsityPuppet is offline   you may: quote & reply,