Skip to content

How to use

Mike edited this page Jun 12, 2021 · 5 revisions

How to use

Add styles

<head>
	<link rel="stylesheet" href="TextGameEngine-styles.css">
</head>

Initialize

import { TextGameEngine, Titles } from "./TextGameEngine.js";
const tge = new TextGameEngine();
tge.init();

Write your game

Print some text to the player

tge.print("Welcome to the Text Game!");
tge.print("New Paragraph", true);
tge.print(); //Empty line

Ask the player for a text or number

If you don't use await you wont get player answer

const num = await tge.num();
const text = await tge.text();

Ask the player to choose something

Don't forget about await

const options = ["Red", "Blue", "Green"];
const index = await tge.choose(options);
const chosen = options[index];

Add pauses so the player has time to read the text

await is also required

await tge.wait(); // until the player clicks continue
await tge.wait(2); // two second pause

Clear screen

tge.clear(); // remove all lines
tge.clear(5); // remove 5 lines

Await and async

When you write functions, don't forget about await and async

async function askQuestion(question: string) 
{
	tge.print(question);
	const answer = await tge.text();
	return answer;
}
tge.print("Hello!")
const answer = await askQuestion("Enter your name:");

Add information

You can add html to the info popup

Get element where you can add yours

const infDiv = tge.getInfDiv();

Add a description of the game

const div = document.createElement("div");
infDiv.appendChild(div);
div.innerText = "A game about a brave knight and a beautiful princess";

Open info popup, for example on start

tge.openInf();

Add colors and styles

Text Formatting