Skip to content

6. Create A Custom Menu

Scotty2Hotty999 edited this page Apr 9, 2015 · 1 revision

To create your own custom menu, you have to go to your script/sys/main.js file or create one.

Inside of that file paste this code in it:

includeFile('menu.js');

// Disable the menu to be able to call the custom one
game.setMenuEnabled(false);

// Update function
while(true) {
    CheckMenu();
}

Create a file called menu.jsand put into your scriptfolder.

var index = 0;
var color1, color2;
var key;

function WasPressed(text) {
	game.removeDrawedRectangle(1);
	game.drawText(22,text+" was pressed",245,135,game.color(255,255,255,1),1);
	game.drawRectangle(1,235,125, 300,35,game.color(122,122,122,0.7),"filled", 0);
}

function showText() {

		color1 = color2 = game.color(255,255,255,1);

		if(index==0) {
			color1 = game.color(125,255,255,1)
		}
		if(index==1) {
			color2 = game.color(125,255,255,1)
		}

		game.drawText(2,"Items",45,135,color1,1);
		game.drawText(3,"Quit Game",45,175,color2,1);
}

function CallMenu() {

	on = true;

	game.drawRectangle(2,35,125, 140,75,game.color(122,122,122,0.7),"filled", 0);

	showText();

	while(true) {
		var key2 = game.getKeyInput([0,1,2,3,4,5]);

		if(key2==1) {
			index++;
			if(index>1) {
				index = 1;
			}
		}
		if(key2==0) {
			index--;
			if(index<0) {
				index = 0;
			}
		}
		if(key2==4) {
			if(index==0) {
				WasPressed('Items');
			}
			if(index==1) {
				WasPressed('Quit Game');
			}
		}

		if(key2==5) {
			game.removeDrawedText(2);
			game.removeDrawedText(3);
			game.removeDrawedText(22);
			game.removeDrawedRectangle(1);
			game.removeDrawedRectangle(2);
			// Removing the arrow keys
			key = game.getKeyInput([5,4]);
			break;
		}

		showText();

	}
}

function CheckMenu() {

	key = game.getKeyInput([5,4]);
	game.log(key)
	if(key==5) {
		game.log('pressed')
		CallMenu();
	}
}

With that done you are now able to call a different menu as before. That menu in menu.js is just an example implementation.