PDA

View Full Version : Object Oriented Programming tutorial


Prozac
02-13-2006, 08:58 PM
Still a little rough, but I think it gets the ideas across for a mindset that is more adaptive to learning gs2.

Please feel free to modify/correct/edit and repost revisions to this as needed.
It is for the newcomers to the gs2 community, and can be openly modified by those in the know. (scroll down for latest version)

Rick
02-13-2006, 11:32 PM
Put it on the GraalBible.

Fox1545
02-13-2006, 11:58 PM
Put it on the GraalBible.
Put it on the Graal Wiki (http://wiki.graal.us).

Skyld
02-14-2006, 12:01 AM
Still a little rough, but I think it gets the ideas across for a mindset that is more adaptive to learning gs2.

Please feel free to modify/correct/edit and repost revisions to this as needed.
It is for the newcomers to the gs2 community, and can be openly modified by those in the know. (scroll down for latest version)
I think the article could do with fluffing out a bit, to make it easier for the average person with no programming knowledge to understand. If you were to start with basic construct of the language, logic behind the construct, why things are what they are and explaining everything in plain English, it might help people more.

Other than that, looking interesting.

Admins
02-14-2006, 12:45 AM
Hmmm Prozac you forgot to put the cup down before leaving the washroom :)
It's a good start I think, although it's more a general programming introduction not only about object oriented programming

ApothiX
02-14-2006, 03:35 PM
Hmm.. I think your section on Constructors is a bit flawed. Should try looking up what a constructor is before writing about it :)

Hmmm Prozac you forgot to put the cup down before leaving the washroom :)o_O What do you mean by this? xD

Codein
02-14-2006, 09:32 PM
o_O What do you mean by this? xD

In his example of an algorithm, with the stuff about what you do in the morning - he forgot to put the cup down.

Prozac
02-15-2006, 01:18 AM
ya, thought I might forget some stuff on the first draft.
thanks for the feedback though. Will see what I can do - or, as mentioned, feel free to 'fluff out' the doc as you see fit and post updates of it on here. I may not get back to it for a while.

ApothiX
02-15-2006, 02:45 AM
In his example of an algorithm, with the stuff about what you do in the morning - he forgot to put the cup down.
Oh, lmao xD

JkWhoSaysNi
02-23-2006, 10:42 PM
I hardly consider GS2 an OO language. It has some OO concepts yeah but it's not completley object-oriented.
While each NPC does act like a class you cant make relationships between them (either inheritance or association) you can 'inherit' the classes in the class list on the server (which are basically deferred classes). I can call functions on an NPC by using triggeraction but really I should be able to do npcname.functionname.

I can't do this: object = new Class(); (Please correct me if i'm wrong) which means I cant pass objects around. Sure there's the player object which can always be accessed but sometimes it can be useful. (Admittedly not often given the usually small nature of scripts in graal.) While GS2 has some OO concepts its OO model is quite limiting. Though of course it is just a small scripting langage and not a full programming language and doesn't really need a sophisticated object model.


Anyway, what you have there might be quite useful to non-programmers but some of the explanations might serve the opposite purpose you're using terms like code block without saying what a code block is also, i'd use GS2 only. Doesn't make sense to say "Here's some code but don't do it like this." it's like teaching java and saying "Heres an example GUI in AWT but you shouldn't use AWT you should use Swing or SWT."

oh well just my $0.03 (Damn inflation.)

Skyld
02-23-2006, 11:57 PM
While each NPC does act like a class you cant make relationships between them (either inheritance or association) you can 'inherit' the classes in the class list on the server (which are basically deferred classes).
Can you think of a need to change the current system?
I can call functions on an NPC by using triggeraction but really I should be able to do npcname.functionname.
public function myFunction()
{
return true;
}
objectName.myFunction();
I can't do this: object = new Class(); (Please correct me if i'm wrong) which means I cant pass objects around.
Yes, you can.
myVar = new TStaticVar();
myWindow = new GuiWindowCtrl("myWindow");
Sure there's the player object which can always be accessed but sometimes it can be useful.
And with player classes, you can add functions to the player object, i.e
player.addMessage("Hello there");

JkWhoSaysNi
02-24-2006, 01:11 AM
Can you think of a need to change the current system?

public function myFunction()
{
return true;
}

objectName.myFunction();




Where does the object name come from? Say I have 2 npc's in a level. I want to call a function on one from the other. Currently you can do this with triggeractions.


Yes, you can.
myVar = new TStaticVar();
myWindow = new GuiWindowCtrl("myWindow");


Yes but I want to my create my own classes. (Just a simple example. I dont really need to do anything like this but it would make gscript more flexible.)


class myClass {
someVar = "something";
someVar2;
public function myClass(a,b) {
this.someVar = a;
this.someVar2 = b;
}
public function stringRepresentation() {
return this.someVar @ this.someVar2;
}
}



myVar = new myClass("One", "Two");
myVar2 = new myClass("Three","Four");
player.chat = myVar.stringRepresntation();
say2(myVar2.stringRepresentation());