Debugging Techniques
Figure Out What's Happening?
We will cover some techniques for debugging your MagiScript code and identifying and fixing errors.
Building Code Step by Step
One of the best ways to identify and fix errors in your code is to build it step by step. This means writing small pieces of code, testing them, and then building on them gradually. This approach makes it easier to identify errors and narrow down where they might be occurring.
Understanding MagiScript Functions
It’s important to have a solid understanding of how MagiScript functions work. This includes understanding how to pass arguments to functions, how to use return values, and how to create and use variables.
Using console.log
Another way to figure out what’s happening in your MagiScript code is to use console.log. This function allows you to log any value in your mini-app and see it displayed in the browser. You can call console.log with many parameters, including numbers and strings. Here are some examples:
// Logging a string
console.log("Hello, world!");
// Logging a number
console.log(42);
// Logging multiple values
console.log("The answer is", 42);
Disable Some Code
Another technique that can be helpful is commenting out parts of your code. Commenting out code involves adding special characters to your code that prevent it from being executed. This can be useful when you want to temporarily disable a part of your code in order to isolate a bug or test a theory about what might be causing an error. To comment out a piece of code in MagiScript, you can simply add two forward slashes (//) before the line or block of code that you want to disable.
console.log('This will run.'); // console.log('It will not run.');
Conclusion
Debugging your MagiScript code is an important part of the development process. By building your code step by step, understanding MagiScript functions, and using console.log to log values, you can identify and fix errors more easily. Remember to take your time and be patient β debugging can be a challenging but rewarding process.
Β
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