Quote from: PatriotClock;1963190whats your second favorite color??? mines orangeHey, that's my color :c
If you need instructions on how to get through the hotels, check out the enclosed instruction book.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts MenuQuote from: PatriotClock;1963190whats your second favorite color??? mines orangeHey, that's my color :c
q = 0;
this.onEnterFrame = function() {
q++;
trace(x);
}
AS3addEventListener(Event.ENTER_FRAME, plus);
var q:Number = 0;
function plus(e:Event)
{
q++;
trace(q);
}
Quote from: MightyBooshClock;1952771Alright Would you mind describing how that code works to me?
var alive = true;
The "Game Over" variable. While it is true, you will keep playing the game. Otherwise the game is over.var path = gamePath0();
Path is the variable that holds where you are in the adventure. You can use numbers or names/phrases.while(alive){
Create a loop that continues until you game over. if(path==1){
path = gamePath1();
} else if(path==2){
//Display Game Over
alive = false;
}
}
An if/else structure used to check where you are in the game. Based on the value of path, it will execute the function according to where you are.function gamePath0(){
Declares a new function. Each time you have a set of choices, you would make a function. Each function contains a prompt and returns a new value for path used to figure out where you are in the game. var path = 0;
Declares path within the function. As long as it is 0, it will keep displaying the prompt. var x;
Just declares x exists, it will be used later. while(path==0){
A while loop that will continue to display the prompt until you give it a valid reply. x = prompt;
The prompt! if(x=='A'){
//display effect
path = 1;
} else if(x=='B'){
//display effect
path = 2;
}
}
Compares x to a set of valid answers. If it matches a value, it will set path to the appropriate value and display a message. If no valid answer is given, it will just ask for a new answer. return path;
}
Returns the value of path. This sends it back to the primary game loop (that first while loop) where the new value will be tested and a new function will be executed, thus continuing your game.//previous code
} else if(path=='VALUE'){
path = gamePathXXX();
} ...
Then you would create the function to go with it:function gamePathXXX()
var path = 0;
while(path==0){
x = prompt;
if(x=='YES'){
//display effect
path = 'GoodResult';
} else if(x=='NO'){
//display effect
path = 'BadResult';
}
}
return path;
}
Quote from: MightyBooshClock;1952741Ok, so I made the curly brackets into colons, without changing the things into if/else statements for now. But now it just runs through each case no matter what I answer.
http://www.codecademy.com/courses/javascript-beginner-en-ZA2rb/0/4
There's the website that I'm using it on. And here's the updated code:
As you can see, no matter what you reply with, it just keeps going to the next case in the code. What would be causing that?
var alive = true;
var path = gamePath0();
while(alive){
if(path==1){
path = gamePath1();
} else if(path==2){
//Display Game Over
alive = false;
}
}
function gamePath0()
var path = 0;
var x;
while(path==0){
x = prompt;
if(x=='A'){
//display effect
path = 1;
} else if(x=='B'){
//display effect
path = 2;
}
}
return path;
}
Quote from: MightyBooshClock;1952607Got another one for ya! So this is just a little choose your own adventure thingy
When I try to run it it says "SyntaxError: Unexpected token {"
switch (variable_to_compare) {
case some_value_1:
//execute code
break;
case some_value_2:
//execute code
break;
default:
//execute code
}
Each case starts with a value which you check against the variable you designated in the switch(). If that variable is equal to that value, it starts to execute all the code after it. When you want it to stop executing code, you add break; which will exit the switch statement. Optionally, you can use a default: case, if there are no matches to any of the case statements, it will execute the code in the default case block.var alive = true;
var path = gamePath0();
while(alive){
if(path==1){
path = gamePath1();
} else if(path==2){
//Display Game Over
alive = false;
}
}
function gamePath0()
var path = 0;
var x;
while(path==0){
x = prompt;
if(x=='A'){
//display effect
path = 1;
} else if(x=='B'){
//display effect
path = 2;
}
}
return path;
}