Wednesday, May 5, 2010

Programming Guidelines/Thoughts for Team Fusion

Some General Programming Guidelines for this Project.

USE CONSTANTS – If you are going to be using a certain number constantly like number of contestants, number of quest items, max number of monsters etc. and these will have a number that will not change throughout the module, set them to a global/local variable and change the name to ALL CAPS. Yes it might be a hassle having to go

int iNumContest = GetGlobalInt(“NUMCONTESTANTS”);

in every script you write but it means if we change anything it will be easier to change your NUMCONTESTANTS variable then go through every script you wrote and change the number itself.

IF YOU CREATE A GLOBAL, WRITE IT DOWN SOMEWHERE – This way when we consolidate our scripts we can look at which global variables we use. I don't know of any way the toolset allows you to track your global variables. If you do know, tell me. It also means if we use the same type of globals, we can easily combine them. We'll be able to initialise them all correctly as well.

Some Reserved globals to use:

Note: You may have to initialise these variables so do so in a TEMPORARY initialise script.

  • gIsMainChal – a boolean check for whether or not it's currently a main challenge – use on scripts/triggers that you want to fire at certain times. I.e if during the main challenge you want special monsters to spawn, check that if gIsMainChal is FALSE then return. Otherwise run the rest of your script.

More pending (if you've got some you need/think we should use let me know/edit this blog post.

NAMING OF VARIABLES – Use hungarian notation like they do in NWScript. Hungarian notation is naming things like object oPC or int iNumItems. Notice the first letter indicates what type it is. I don't like it but NWScript uses it so go with the flow. (Anna and Stephen use it as well).

Globals start with a g. locals don't start with an l, they are just standard type notation.

NAMING OF SCRIPTS – use something like grouping_nameofscript, When I say grouping I mean labeling it under a group of where/what the scripts does. So if I have a fitness related script I label it fit_whateverA, or fit_blahB. This way when I'm looking for scripts it makes it easier to find. And even easier when we combine our many scripts together. I'll leave it to your discretion how you name your scripts but please don't go overboard and have like forest_mainquest_end_startending.

It should be simple like forest_mq_startending. Or whatever.

LEARN TO REFACTOR YOUR CODE – Code refactoring is an important skill for programmers. What it means is if you find yourself doing a set of functions repeatedly, think about putting it in another method/function and calling it whenever you need it. Also consider doing this if you find your function/script getting too big.

E.g. I found myself doing this a lot:

object oObj = GetObjectByTag(sTag);

int j = GetLocalVariable(oObj, sVarName);  


so I wrote a function that does it for me

VarType getLocalVarFromTag(sTag, sVarName)

{

object oTarget = GetObjectByTag(sTag);

return GetLocalVariable(oTarget, sVarName);

}

then just import that script into the scripts I'm writing and whenever I need a variable and all I have is a tagname I can just go

int j = getLocalVarFromTag(sTag, sVarName);

If you read the GS board (which I doubt anyone does) I put up that list of functions along with instruction, so use it if you need it because the script is going to be in the final Module anyway.

COMMENT YOUR SCRIPTS - Do it just they teach us in Programming 1. Not too verbose and not stating the obvious. Also ADD A COMMENT HEADER TO THE TOP OF YOUR SCRIPTS. In it should be your name, student number and what this script does. If/When we modify each other's scripts, then add on your name, student number and what/how you modified the script.

Artists/Designer!!!

NAME YOUR TAGS APPROPRIATELY. - Don't make them too long/short, use _, Also if you're creating a series of objects, think about naming your tags in a format like magic_qItem_1, magic_qItem_2, magic_qItem_3 (q for quest) or whatever, cos it makes it easier for us programmers to use and iterate through your items.

Rather than going:

magic_qItem_sword, magic_qItem_hammer, magic_qItem_crystal.

Might want to think about doing this for the contestants as well.

Give us a lit of which number corresponds to which object etc.


WRITE DOWN A LIST OF TAGS – I think this is a given.

More if I think up any.

Also side note, I added my gmail account as an author of this blog only. Because everytime I logged into the team cake gmail all my google stuff disappeared to team cake google stuff. which is bad. Nick, if you have a gmail and you want access instead of having to log in as team cake, log in as team cake first then go to blog settings -> permissions then send an invite to your gmail. Log out and log into your own gmail and you should have received the email.


Google is awesome for shared stuff albeit evil everything else.

2 comments: