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