The Bloko Forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

The Bloko Forums


 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log in  

 

 Package/Parent Syntax Tutorial.

Go down 
3 posters
AuthorMessage
Admin
Admin
Admin


Number of posts : 137
Location : Here.... There....
Blockland ID : 2037, 6145
Reputation : 5
Points : 5625

Package/Parent Syntax Tutorial. Empty
PostSubject: Package/Parent Syntax Tutorial.   Package/Parent Syntax Tutorial. EmptyThu Mar 19, 2009 1:47 pm

We all want to be able to make our own modifications to Blockland, whether to add new features, set or work around limitations, or change the way the game is played. The problem is that all of the code that controls game play is stored in encrypted files. One great feature that Blockland, and the Torque Game Engine it's based on, supports is encapsulation. For those of you that are new to programming, encapsulation at its most basic level means storing one item within another. Take a plastic Easter egg for example. The plastic egg is the container (the 'Parent') and the pieces of candy within are its children. You can't really change the way the egg (or 'Parent') works without destroying it, but you can change its candy (or children).
In Blockland, the Parent is the main game code. All the code stored in those .dso files cannot be changed. Now, when someone creates normal add-on code that does not overwrite any of the game's built-in functions, the creator's code becomes part of the main game code. If you overwrite a built-in function (serverCmdPlantBrick), you might lose a very important piece of functionality.
How do we get around this? Packages! Here's an example package:
Code:
package NewPackage
{
 function paintProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
 {
                <any special actions you want performed when this projectile collides>
  Parent::onCollision(%this,%obj,%col,%fade,%pos,%normal);
 }
};
In the above example, our NewPackage includes a method that adds to functionality of the paint can's projectile collision. Note that, after inserting our own, new code, we call the Parent (main game code) to run its normal collision code. We pass to the Parent::onCollision() method the exact same number of parameters that our method receives.
Now, before you run off to try this on your own, there's one very important line of code you'll need to add here:
Code:
activatePackage(NewPackage);
Packages in Blockland or TGE can be enabled or disabled using activatePackage(<package name>) or deactivatePackage(<package name>). If a package if not activated, you cannot make use of its specialized methods.
Well, those are the basics. Just remember:
Parent (main game code.)
{
Packages (collections of our methods that extend the ones built into the game.)
{
Methods (individual functions that we create. must call Parent to retain original functionality.)
}
}


[Thanks to Trader for making this.]
Back to top Go down
https://blokoforumstest.forumotion.com
Placid
Moderator
Placid


Number of posts : 198
Location : Somewhere. Don't ask.
Blockland ID : 5173
Reputation : 0
Points : 5634

Package/Parent Syntax Tutorial. Empty
PostSubject: Re: Package/Parent Syntax Tutorial.   Package/Parent Syntax Tutorial. EmptySat Mar 28, 2009 5:09 am

As normal, I have absolutely no clue what this is.
Back to top Go down
http://www.placidsite.webs.com
Blocker
Cool Bloko
Blocker


Number of posts : 143
Location : In the darkness of the night
Blockland ID : 7232
Reputation : 1
Points : 5617

Package/Parent Syntax Tutorial. Empty
PostSubject: Re: Package/Parent Syntax Tutorial.   Package/Parent Syntax Tutorial. EmptyMon Apr 13, 2009 4:19 pm

Placid wrote:
As normal, I have absolutely no clue what this is.

Same here bro....
Back to top Go down
Sponsored content





Package/Parent Syntax Tutorial. Empty
PostSubject: Re: Package/Parent Syntax Tutorial.   Package/Parent Syntax Tutorial. Empty

Back to top Go down
 
Package/Parent Syntax Tutorial.
Back to top 
Page 1 of 1
 Similar topics
-
» Blender tutorial (make your own add-on!)

Permissions in this forum:You cannot reply to topics in this forum
The Bloko Forums :: Modding Discussion :: Coding Help-
Jump to: