The Bloko Forums

HomeHome  FAQFAQ  SearchSearch  MemberlistMemberlist  UsergroupsUsergroups  RegisterRegister  Log in  

Share | 

 Package/Parent Syntax Tutorial.

Go down 

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

PostSubject: Package/Parent Syntax Tutorial.   Thu 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:
package NewPackage
 function paintProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
                <any special actions you want performed when this projectile collides>
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:
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.]

Want a Signiture? There's Details coming soon.
Back to top Go down
View user profile

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

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

As normal, I have absolutely no clue what this is.
Back to top Go down
View user profile
Cool Bloko

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

PostSubject: Re: Package/Parent Syntax Tutorial.   Mon 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
View user profile
Sponsored content

PostSubject: Re: Package/Parent Syntax Tutorial.   

Back to top Go down
Package/Parent Syntax Tutorial.
Back to top 
Page 1 of 1
 Similar topics
» Curl Tutorial!
» AOE_Fan's RMS Command Tutorial
» Mipedians

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