๐ŸŒ Your Peek Just Went Global
๐Ÿšš Shipping from 12 USD
๐Ÿ’ฐ DEALS OF THE DAY

Time Practice

Introduction

You should practice using the remote, so you can enter any time confidently without watching. The Time Practice mini-game is here to help you.

The app generates a random time, and you have to enter it correctly. When connected to a browser, it will also tell you the time with an Audio Assistant, and give you a feedback if you were successful or not.

Here’s the MagiScript code of the built-in Atom Practice mini-app, which is using some of the latest language features:

				
					let time = ''; // the time entered
let timeout; // will contain a timeout ID
let startTimeout; // delay at app start
let targetTime; // the time you have to enter

function main() {
  ps.connect();
  startTimeout = setTimeout(start, 2000);
}

function start() {
  voice.say('Ready?');
  generateTime();
}

// prints the target time and the time input
function printFormattedTime() {
  ps.print(`${targetTime.text}\n<${time}>`);
}

function generateTime() {
  targetTime = parseTime(rand(12), rand(60));
  voice.say(targetTime.text);
  printFormattedTime();
}

const layout = [ // button layour
  '1', '2', '3',
  '4', '5', '6',
  '7', '8', '9',
  'c', '0', '<'
];

function check() {
  clearTimeout(timeout); // don't trigger send
  if (time === '') return; // nothing to set

  const enteredTime = parseTime(time);

  // is it correct?
  if (targetTime.text === enteredTime.text) {
    ps.print('CORRECT');
    const goodIndex = rand(6);
    const goodMessages = ['GOOD', 'NICE', 'CORRECT', 'PERFECT', 'GREAT', 'EXCELLENT'];
    voice.say(goodMessages[goodIndex]);
    atom.vibrate('.');
    setTimeout(generateTime, 500);
    time = '';
  } else {
    ps.print('NOPE');
    voice.say('NOT CORRECT');
    atom.vibrate('=');
    setTimeout(printFormattedTime, 500);
  }
}

function onButtonClick(buttonId) {
  if (targetTime === undefined) return; // not ready yet
  const processAfterFourDigits = config.get('atomtime.submit.after_four_digits');

  const key = layout[buttonId];
  switch (key) {
    case 'c':
      check();
      return;
    case '<':
      time = strSub(time, 0, -1);
      break;
    default:
      if (strLen(time) < 4) time += key;
      if (strLen(time) >= 4 && processAfterFourDigits) {
        check();
        return;
      }

      break;
  }

  // delete the previous timer, and start a new
  clearTimeout(timeout);
  const processAfter = config.get('keyboard.submit.after');
  if (processAfter > 0) timeout = setTimeout(() => {
    check();
  }, processAfter);

  // display the times
  printFormattedTime();
}

// there are events coming from the SB Watch and the buttons of Atom
function onEvent(e) {
  if (e.source === 'ps:ble' && e.type === 'connected') {
    ps.print('Atom\nPractice');
    clearTimeout(startTimeout);
    startTimeout = setTimeout(start, 2000);
    return;
  }

  if (e.source === 'atom:button') {
    const buttonId = parseInt(e.value);
    if (e.type === 'click') {
      onButtonClick(buttonId);
    }
    if (strSub(e.type, 0, 5) === 'click' && strLen(e.type) === 6) {
        const clickCount = parseInt(strCharAt(e.type, 5));
        for (let i = 0; i < clickCount; i++) {
            onButtonClick(buttonId);
        }
    }
  }
}
				
			

Devices & MagiScript

โš›๏ธ Atom Remote

๐Ÿ”ข Quantum

๐Ÿคนโ€โ™‚๏ธ MagiScript Language

๐Ÿคนโ€โ™‚๏ธ MagiScript Examples

๐Ÿคนโ€โ™‚๏ธ MagiScript Tutorials

General

๐Ÿ“ƒ Examples

Atom

๐Ÿ“ƒ Atom Time

๐ŸŽž๏ธ Time Practice

๐Ÿ“ƒ Atom Pi (Pi Revelations)

๐Ÿ“ƒ Atom Drum

๐ŸŽž๏ธ Atom Stack

๐Ÿ“ƒ Atom Square

๐Ÿ“ƒ Atom Level

๐Ÿ“ƒ Atom THMPR

๐Ÿ“ƒ Poker Hands

๐Ÿ“ƒ Keyboard Numeric

๐Ÿ“ƒ Keyboard NOKIA

๐Ÿ“ƒ Keyboard Cursor

๐Ÿ“ƒ Keyboard Media

๐Ÿ“ƒ Keyboard Custom