Discuss Scratch
- Discussion Forums
- » Developing Scratch Extensions
- » My Adventure Game Extension using JavaScript!
- Cowboy433
-
100+ posts
My Adventure Game Extension using JavaScript!
Hello, I got a little bored and decided to make this little game. It is a very simple and neat little game using JavaScript prompts and alerts to make a game. Go ahead and try it out using the console in the scratch editor, and paste the code below:
(function(ext) {
ext._shutdown = function() {};
ext._getStatus = function() {
return {status: 2, msg: ‘Ready’};
};
ext.game_play_n_adventure = function() {
var troll = prompt(“You're walking through the forest, minding your own business, and you run into a troll! Do you FIGHT him, PAY him, or RUN?”).toUpperCase();
switch(troll) {
case ‘FIGHT’:
var strong = prompt(“How courageous! Are you strong (YES or NO)?”).toUpperCase();
var smart = prompt(“Are you smart?”).toUpperCase();
if(strong === ‘YES’ || smart === ‘YES’) {
alert(“You only need one of the two! You beat the troll–nice work!”);
} else {
alert(“You're not strong OR smart? Well, if you were smarter, you probably wouldn't have tried to fight a troll. You lose!”);
}
break;
case ‘PAY’:
var money = prompt(“All right, we'll pay the troll. Do you have any money (YES or NO)?”).toUpperCase();
var dollars = prompt(“Is your money in Troll Dollars?”).toUpperCase();
if(money === ‘YES’ && dollars === ‘YES’) {
alert(“Great! You pay the troll and continue on your merry way.”);
} else {
alert(“Dang! This troll only takes Troll Dollars. You get whomped!”);
}
break;
case ‘RUN’:
var fast = prompt(“Let's book it! Are you fast (YES or NO)?”).toUpperCase();
var headStart = prompt(“Did you get a head start?”).toUpperCase();
if(fast === ‘YES’ || headStart === ‘YES’) {
alert(“You got away–barely! You live to stroll through the forest another day.”);
} else {
alert(“You're not fast and you didn't get a head start? You never had a chance! The troll eats you.”);
}
break;
default:
alert(“I didn't understand your choice. Hit the flag and try again, this time picking FIGHT, PAY, or RUN!”);
}
};
// Block and block menu descriptions
var descriptor = {
blocks: [
,
]
};
ScratchExtensions.register('Adventure Game Extension', descriptor, ext);
})({});Since a lot of people do not know how to get to the console, I will post a link to my GitHub with the extensions file on it.
Last edited by Cowboy433 (March 8, 2016 03:11:14)
- _Comicfan_
-
1000+ posts
My Adventure Game Extension using JavaScript!
Cool! 

(function(ext) {
ext._shutdown = function() {};
ext._getStatus = function() {
return {status: 2, msg: ‘Ready’};
};
ext.game_play_n_adventure = function() {
var troll = prompt(“You're walking through the forest, minding your own business, and you run into a troll! Do you FIGHT him, PAY him, or RUN?”).toUpperCase();
switch(troll) {
case ‘FIGHT’:
var strong = prompt(“How courageous! Are you strong (YES or NO)?”).toUpperCase();
var smart = prompt(“Are you smart?”).toUpperCase();
if(strong === ‘YES’ || smart === ‘YES’) {
alert(“You only need one of the two! You beat the troll–nice work!”);
} else {
alert(“You're not strong OR smart? Well, if you were smarter, you probably wouldn't have tried to fight a troll. You lose!”);
}
break;
case ‘PAY’:
var money = prompt(“All right, we'll pay the troll. Do you have any money (YES or NO)?”).toUpperCase();
var dollars = prompt(“Is your money in Troll Dollars?”).toUpperCase();
if(money === ‘YES’ && dollars === ‘YES’) {
alert(“Great! You pay the troll and continue on your merry way.”);
} else {
alert(“Dang! This troll only takes Troll Dollars. You get whomped!”);
}
break;
case ‘RUN’:
var fast = prompt(“Let's book it! Are you fast (YES or NO)?”).toUpperCase();
var headStart = prompt(“Did you get a head start?”).toUpperCase();
if(fast === ‘YES’ || headStart === ‘YES’) {
alert(“You got away–barely! You live to stroll through the forest another day.”);
} else {
alert(“You're not fast and you didn't get a head start? You never had a chance! The troll eats you.”);
}
break;
default:
alert(“I didn't understand your choice. Hit the flag and try again, this time picking FIGHT, PAY, or RUN!”);
}
};
// Block and block menu descriptions
var descriptor = {
blocks: [
,
]
};
ScratchExtensions.register('Adventure Game Extension', descriptor, ext);
})({});
- Discussion Forums
- » Developing Scratch Extensions
-
» My Adventure Game Extension using JavaScript!