diff --git a/src/API.ts b/src/API.ts index 731109b..067824e 100644 --- a/src/API.ts +++ b/src/API.ts @@ -96,6 +96,7 @@ export class UserAPI { public scale_aid: string | number | undefined = undefined; public hydra: any; public onceEvaluator: boolean = true; + public forceEvaluator: boolean = false; load: samples; public global: { [key: string]: any }; @@ -1941,6 +1942,14 @@ export class UserAPI { this._logMessage(message); }; + logOnce = (message: any) => { + if(this.onceEvaluator) { + console.log(message); + this._logMessage(message); + this.onceEvaluator = false; + } + } + scale = getScaleNotes; nearScales = nearScales; diff --git a/src/Evaluator.ts b/src/Evaluator.ts index 2df2272..f877a9b 100644 --- a/src/Evaluator.ts +++ b/src/Evaluator.ts @@ -81,6 +81,7 @@ export const tryEvaluate = async ( ); addFunctionToCache(candidateCode, newFunction); } else { + application.api.logOnce("Compilation error!"); await evaluate(application, code, timeout); } } diff --git a/src/KeyActions.ts b/src/KeyActions.ts index ad0603c..73d4dce 100644 --- a/src/KeyActions.ts +++ b/src/KeyActions.ts @@ -106,6 +106,7 @@ export const registerOnKeyDown = (app: Editor) => { event.preventDefault(); app.currentFile().candidate = app.view.state.doc.toString(); app.api.onceEvaluator = true; + app.api.forceEvaluator = true; tryEvaluate(app, app.currentFile()); app.flashBackground("#404040", 200); } @@ -115,7 +116,7 @@ export const registerOnKeyDown = (app: Editor) => { event.preventDefault(); app.api.clearPatternCache(); app.currentFile().candidate = app.view.state.doc.toString(); - app.api.onceEvaluator = true; + app.api.forceEvaluator = true; tryEvaluate(app, app.currentFile()); app.flashBackground("#404040", 200); } diff --git a/src/documentation/basics/code.ts b/src/documentation/basics/code.ts index 4851049..b830cd8 100644 --- a/src/documentation/basics/code.ts +++ b/src/documentation/basics/code.ts @@ -23,7 +23,7 @@ The code you enter in any of the scripts is evaluated in strict mode. This tells - **about variables:** the state of your variables is not kept between iterations. If you write let a = 2 and remove that value from your script, **it will crash**! Variable and state is not preserved between each run of the script. There are other ways to deal with variables and to share variables between scripts! Some variables like **iterators** can keep their state between iterations because they are saved **with the file itself**. There is also **global variables**. - **about errors and printing:** your code will crash! Don't worry, we do our best to make it crash in the most gracious way possible. Most errors are caught and displayed in the interface. For weirder bugs, open the dev console with ${key_shortcut( "Ctrl + Shift + I", - )}. You cannot directly use console.log('hello, world') in the interface but you can use log(message) to print a one line message. You will have to open the console as well to see your messages being printed there! + )}. You cannot directly use console.log('hello, world') in the interface but you can use log(message) to print a one line message. You will have to open the console as well to see your messages being printed there! You can also use logOnce(message) to print a message only once (or everytime you press Ctrl+Shift+Backspace). - **about new syntax:** sometimes, we had some fun with JavaScript's syntax in order to make it easier/faster to write on stage. && can also be written :: or -> because it is faster to type or better for the eyes! # Common idioms