Game Development Reference
In-Depth Information
Examining JavaScript code
JavaScript is a very popular web language. It is much easier to code in than most other pro-
gramming languages.
Let's take a look at some examples of JavaScript code.
var score;
var timescale = 1.2;
var name = "John Bura";
var playerName;
You will notice that all of the variables are simply called var instead of Int , Bool ,
String , or Real . This means that, until you initialize the variable, var can be whatever
you want it to be.
So in this case, score is not a number—it is simply a variable. However, timescale is
a number variable because we have initialized it as such with the = sign. Similarly, var
name is a string because we initialized it, while var playerName is simply a variable.
Their nature doesn't become set until they are initialized. JavaScript has become popular
because you can have less precise code and still make it work.
Now, in JavaScript, there is something that doesn't happen in most environments—you can
mix and match variables. I strongly advise not doing this. As a programmer who started
with integer and string values, I highly suggest you keep your variables organized. If you
mix and match variables and simply don't care, you will have a hard time releasing your
game—and releasing is important.
Since Construct 2 is exported in JavaScript, it is important to have a basic understanding of
how it works. It is also important to know what kinds of variables are present because, even
in JavaScript, you have to use different kinds of variables.
Search WWH ::




Custom Search