⌚SB Watch 2
🚚 Free fedex shipping from 97 $
🌎 WORLDWIDE SHIPPING for 25 $

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);
        }
    }
  }
}
				
			

General

πŸ“ƒΒ First Steps

MagiScript Editor

πŸ“ƒΒ Basics

πŸ“ƒΒ Running Your First Program

πŸ“ƒΒ App Store

πŸ“ƒΒ Atom Settings (Editor)

πŸ“ƒΒ Debugging Techniques

Examples

πŸ“ƒΒ 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

Input/Output

πŸ“ƒΒ Buttons

πŸ“ƒΒ Vibration Motor

πŸ“ƒΒ RGB LED

πŸ“ƒΒ Devices

πŸ“ƒΒ PeekSmith

πŸ“ƒΒ SB Watch

πŸ“ƒΒ Bluetooth Keyboard

πŸ“ƒΒ Bluetooth Mouse

πŸ“ƒΒ Timers

πŸ“ƒΒ Database

πŸ“ƒΒ Events

πŸ“ƒΒ System (exit, sleep, rand)

πŸ“ƒΒ Objects (card, time)

Language

πŸ“ƒΒ Summary

πŸ“ƒΒ Comments

πŸ“ƒΒ Variable Declarations

πŸ“ƒΒ Operators

πŸ“ƒΒ Control Flow

πŸ“ƒΒ Functions

πŸ“ƒΒ Numbers

πŸ“ƒΒ Strings

πŸ“ƒΒ Arrays

πŸ“ƒΒ Objects

πŸ“ƒΒ Uint8Array