{} 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?
%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?
Employee Michael Perry
ZombieShortbus
%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.