A dip into JavaScript.
Before I begin. var is a variable. You need to declare your variables before you start writing code so the code will execute properly. Declaring a function goes like this:
function Update(){
//Insert your code here....
}
Anything between {} would be executed when the function was called. The brackets need to all be closed by the end of the script or it will not execute properly
You usually want to end each line of code that's not declaring a function, class, or if statement with ;. So it could look something like this
function Update(){
transform.Translate(0, 0, 1);
}
You can insert little comments that you can read to keep up with your script and are not executed by beginning with //. So in the end...
//moving the object
function Update(){
transform.Translate(0, 0, 1);
}
Two more side notes... The transform is the object that the script is attached to. The Update function is called every frame that is rendered. Which for my little e machine computer, is around 35 times a second.
So I made a JavaScript for keeping up with the levels of the character. I'll explain it as best as I can.
Heres the code:
class BendingCapability {
var experience = 0.0;
var minimumExperience = 100;
var name = "";
var level = 0;
//getting name..
function BendingCapability(name) {
this.name = name;
}
//debugging purposes
function getName() {
return name;
}
//checking exprience, leveling up.
function updateLevel() {
if(check()) {
minimumExperience += minimumExperience * 1.8;
level = level + 1;
}
}
//checking experience
function check() {
return experience >= minimumExperience;
}
}
//declaring different classes
var earthManipulation = new BendingCapability("Earth");
var fireManipulation = new BendingCapability("Fire");
var waterManipulation = new BendingCapability("Water");
var electricManipulation = new BendingCapability("Electric");
var airManipulation = new BendingCapability("Air");
//checking level up..
function Update(){
earthManipulation.updateLevel();
fireManipulation.updateLevel();
waterManipulation.updateLevel();
electricManipulation.updateLevel();
airManipulation.updateLevel();
}
So In the beginning I declared a class and named is BendingCapability. (Note:In JavaScript you need to make sure that you match up capitalization, spelling, spacing, and so on...) Creating the Class is almost like creating a template for each Level category to follow. I created several functions here that make up the template. But I first started with declaring the variables. Experience is how much experience the player has with the level. minimumExperience is how much experience is needed to level up. The name is just simply the name of the level. and level is the level of level category (earth, fire, ect.) So the function BendingCapability(name) got the name of the level. To avoid.. or lessen the confusion I will start calling it skill. Ignore the debugging purposses for now. The function updateLevel is called to see if the required needs are met to level up.
So...
function updateLevel(){
if(check()){
The function has a nested if statement. The if requirements are called within the (). In this case it's calling a function further down the script.
function check(){
return experience >= minimumExperience;
}
All this does is see if the experience is greater than or equal to the minimum Experience required to level up, and if it is, it returns it true.
So if the check returns true, then:
minimumExperience += minimumExperience * 1.8;
level = level +1;
This adds a level (level up) to the skill that met the required experience. Then we added the minimumExperince to the existing minimum experience so it would not loop and continue to level up. The we multiplied whats being added to it by 1.8 so you would have to gather alittle more experience than you did last time to level up again.
Now to declare a skill with the class you say...
var earthManipulation = new BendingCapability("Earth");
what this does is creates a whole class just for Earth Manipulation. Which what we called earth.
the type of var = BendingCapability, which is a class.
Then lastly the Update function....
function Update(){
earthManipulation.updateLevel;
}
Remember that the update function is called every frame. We say earthManipulation to look at its class, then within the class we call upon its updateLevel function. Which calls upon the check function to see if the skill has met the required experience to level up, and if it has, It executes the rest of the updateLevel function.
Very long I know.
Comment what you think, be a critic. I need those before I can have fans. Sorry I'm new to javascript so i might not be doing things the best they could be done. Sudgest or complain. correct me. Anything to make this blog better
Before I begin. var is a variable. You need to declare your variables before you start writing code so the code will execute properly. Declaring a function goes like this:
function Update(){
//Insert your code here....
}
Anything between {} would be executed when the function was called. The brackets need to all be closed by the end of the script or it will not execute properly
You usually want to end each line of code that's not declaring a function, class, or if statement with ;. So it could look something like this
function Update(){
transform.Translate(0, 0, 1);
}
You can insert little comments that you can read to keep up with your script and are not executed by beginning with //. So in the end...
//moving the object
function Update(){
transform.Translate(0, 0, 1);
}
Two more side notes... The transform is the object that the script is attached to. The Update function is called every frame that is rendered. Which for my little e machine computer, is around 35 times a second.
So I made a JavaScript for keeping up with the levels of the character. I'll explain it as best as I can.
Heres the code:
class BendingCapability {
var experience = 0.0;
var minimumExperience = 100;
var name = "";
var level = 0;
//getting name..
function BendingCapability(name) {
this.name = name;
}
//debugging purposes
function getName() {
return name;
}
//checking exprience, leveling up.
function updateLevel() {
if(check()) {
minimumExperience += minimumExperience * 1.8;
level = level + 1;
}
}
//checking experience
function check() {
return experience >= minimumExperience;
}
}
//declaring different classes
var earthManipulation = new BendingCapability("Earth");
var fireManipulation = new BendingCapability("Fire");
var waterManipulation = new BendingCapability("Water");
var electricManipulation = new BendingCapability("Electric");
var airManipulation = new BendingCapability("Air");
//checking level up..
function Update(){
earthManipulation.updateLevel();
fireManipulation.updateLevel();
waterManipulation.updateLevel();
electricManipulation.updateLevel();
airManipulation.updateLevel();
}
So In the beginning I declared a class and named is BendingCapability. (Note:In JavaScript you need to make sure that you match up capitalization, spelling, spacing, and so on...) Creating the Class is almost like creating a template for each Level category to follow. I created several functions here that make up the template. But I first started with declaring the variables. Experience is how much experience the player has with the level. minimumExperience is how much experience is needed to level up. The name is just simply the name of the level. and level is the level of level category (earth, fire, ect.) So the function BendingCapability(name) got the name of the level. To avoid.. or lessen the confusion I will start calling it skill. Ignore the debugging purposses for now. The function updateLevel is called to see if the required needs are met to level up.
So...
function updateLevel(){
if(check()){
The function has a nested if statement. The if requirements are called within the (). In this case it's calling a function further down the script.
function check(){
return experience >= minimumExperience;
}
All this does is see if the experience is greater than or equal to the minimum Experience required to level up, and if it is, it returns it true.
So if the check returns true, then:
minimumExperience += minimumExperience * 1.8;
level = level +1;
This adds a level (level up) to the skill that met the required experience. Then we added the minimumExperince to the existing minimum experience so it would not loop and continue to level up. The we multiplied whats being added to it by 1.8 so you would have to gather alittle more experience than you did last time to level up again.
Now to declare a skill with the class you say...
var earthManipulation = new BendingCapability("Earth");
what this does is creates a whole class just for Earth Manipulation. Which what we called earth.
the type of var = BendingCapability, which is a class.
Then lastly the Update function....
function Update(){
earthManipulation.updateLevel;
}
Remember that the update function is called every frame. We say earthManipulation to look at its class, then within the class we call upon its updateLevel function. Which calls upon the check function to see if the skill has met the required experience to level up, and if it has, It executes the rest of the updateLevel function.
Very long I know.
Comment what you think, be a critic. I need those before I can have fans. Sorry I'm new to javascript so i might not be doing things the best they could be done. Sudgest or complain. correct me. Anything to make this blog better
Comments
Post a Comment