Whats needed next

Location of the Videos
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Whats needed next

Post by hallsofvallhalla »

ok now try to do math with those numbers, then make a string do stuff with those numbers. Use those variables in a complicated function...

Go ahead and get use to the wrong way and not define them. You will pay for it in the end.
Normal variables

It is good practice to pre-define all variables using the var keyword. It is possible to define the variable, leaving its value undefined, or assigning a value immediately, or even to define multiple variables in a single command:

var variablename;
var variablename = value;
var vari1 = value, vari2 = anotherValue, vari3;

JavaScript is fairly lenient, and will create a global variable if you forget to use the 'var' keyword, but you assign a value to an undeclared variable (if you attempt to read the value of an undeclared variable, it will throw an error, as discussed below). However, this can lead to problems if you end up accidentally overwriting variables from another scope (this will be covered in the chapter on Functions). Once a variable is defined do not use 'var variablename' again unless you wish to completely overwrite the variable. It makes no sense to redeclare a variable with the var keyword within the same scope, but browsers will not complain if you do it.
http://www.howtocreate.co.uk/tutorials/ ... /variables
seanoseanohay
Posts: 25
Joined: Mon Mar 15, 2010 8:27 pm

Re: Whats needed next

Post by seanoseanohay »

Good coding practice cannot really be seen as a bad thing I suppose.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Whats needed next

Post by Jackolantern »

It is just more clear for the coder. Beyond any issues of calculations that don't come out right because it inferred the wrong type, it helps things stay organized to choose one location to initialize all variables for each scope. That way you have one place to look for each section when you need to refresh your memory on what variable you need to use. Overwriting global variables because you forgot you already declared a variable with that name is a very common mistake (and one of the most compelling reasons against the use of global variables). Declaring variables when you use them compounds this problem even more, because now it will become almost impossible to find a variable once your program becomes hundreds or thousands of lines long.
The indelible lord of tl;dr
Dizuki
Posts: 217
Joined: Tue Jun 22, 2010 9:10 pm

Re: Whats needed next

Post by Dizuki »

One of the aspects i wanted for my game was a Player vs player function in fact its the base of my game. So I'd appreciate it if you did a video on that or a automated battle sequence tutorial. Or if you already have a tutorial somewhere about that could you let me know.
Rastan
Posts: 126
Joined: Tue Apr 13, 2010 1:48 am

Re: Whats needed next

Post by Rastan »

If you look in the coding section I was getting help on an autoattack system like that and there's a few codes posted for it.
Dizuki
Posts: 217
Joined: Tue Jun 22, 2010 9:10 pm

Re: Whats needed next

Post by Dizuki »

Oh thanks, :) I'll go check that out in the morning, its getting late and i'd rather not start another project.
Post Reply

Return to “Older Browser MMO Videos”