Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Test automatically your game

A topic by ildede created Dec 29, 2023 Views: 105
Viewing posts 1 to 1
(1 edit)

Hi!

Being sure to always reach all the string in game, or test weird paths of the game, could be difficult.
Lots of command need to be inserted by hand, and, there is no copy-paste 馃槵

If you know how to play a little in the browser's console (or in the JS files): I'm happy to share with you something that you can use to magically type your commands, always in the same order...  without typing

Let's start with a function that let us simulate the typing of any given word.

function insert(input) {
  input.split('')
    .forEach((c, i) => {
      setTimeout(
        () => document.dispatchEvent(new KeyboardEvent('keydown', { keyCode: c.charCodeAt(0), key: c })),
        i * 4
      )
    });
  setTimeout(() => document.dispatchEvent(new KeyboardEvent('keydown', { keyCode: 13 })), input.length * 5);
 }

If you paste this function in the console, you can now use it like

insert("OPEN DOOR");
insert("TAKE THE BONE"):

Not so useful, as you need to type all instruction one by one (but at least you can copy-paste them  馃憖

Adding some more JS magic we can have a list of words to iterate with a simple function, and then, use only one command to "go to the next value".

function* inputsIterator(inputs) {
  let index = 0;
  while (index < inputs.length) {
    yield inputs[index];
    index++;
  }
}
const iterator = inputsIterator([
  "OPEN DOOR",
  "TAKE BONE"
]);

With all the above done you can write 

 insert(iterator.next().value);

in the console and the first time it will insert "OPEN DOOR", the second time "TAKE THE BONE".


Is it clear? Yes, No? Available for explanation in case.
PS: This does not work on itch.io, but only when you test locally.