Game Development Community

{} vs {}; help?

by jerryg7rk3w · in Game Design and Creative Issues · 03/14/2011 (2:29 pm) · 2 replies

// Create a missile

%this.playerMissile = new t2dStaticSprite()
{
scenegraph = %this.scenegraph;
class = PlayerMissile;
missileSpeed = %this.missileSpeed;
player = %this;
}; //<= ******** So what does this simicolon do anyways ********

// Fire the missile

%this.playerMissile.fire();
} //<= ******** Why does this not have one********

This is the code i dont understand, ive been told that }; is just bad coding to end a function with, but if you try to remove the simicolon then i get an error in the console, so what does that simicolon do anyways in this situation? Why is it needed?

#1
03/14/2011 (6:06 pm)
The following is a declaration of an object, which always needs a semicolon:
%this.playerMissile = new t2dStaticSprite()
{
   scenegraph = %this.scenegraph;
   class = PlayerMissile;
   missileSpeed = %this.missileSpeed;
   player = %this;
};

You do not need a semicolon when you are blocking off code, as you would with a control statement:

if(%someVariable)
{
   %this.playerMissile.fire();
}

for(%val = 0; %val < 10; %val++)
{
   echo("Looping");
}

Lines with a semicolon mean it is executed code. Lines without it are encapsulation.
#2
03/15/2011 (9:38 pm)
Thanks i appreciate the help.