From af8480aca20cc1b3c1eaf9d10e2fc46f0e9e0795 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Sun, 15 Dec 2019 23:06:35 +0100 Subject: [PATCH] added global variable access methods to the new Snap! API --- HISTORY.md | 2 ++ src/gui.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index 3adb89f9..6be264a5 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -6,6 +6,7 @@ * export pen trails as SVG * access pen trails as SVG_Costume: new "pen vectors" reporter variant of "pen trails" * new Snap! API: programmatically broadcast messages and optionally wait from outside Snap! + * new Snap! API: programmatically get and set global variables from outside Snap! * **Notable Changes:** * when creating a costume from pen trails (raster or vector) make its rotation center the position of the sprite * **Notable Fixes:** @@ -16,6 +17,7 @@ ### 2019-12-15 * gui, threads: new Snap! API: programmatically broadcast messages and optionally wait from outside Snap! +* gui: added global variable access methods to the new Snap! API ### 2019-12-13 * added direct relabelling option to pen trails blocks' context menus diff --git a/src/gui.js b/src/gui.js index 6cc5e18e..43dc021a 100644 --- a/src/gui.js +++ b/src/gui.js @@ -6102,6 +6102,23 @@ IDE_Morph.prototype.broadcast = function(message, callback) { }); }; +IDE_Morph.prototype.getVarNames = function () { + // return an array of all global variable names + return this.stage.globalVariables().names(); +}; + +IDE_Morph.prototype.getVar = function (name) { + // return the value of the global variable indicated by name + // raise an error if no global variable of that name exists + return this.stage.globalVariables().getVar(name); +}; + +IDE_Morph.prototype.setVar = function (name, value) { + // set the value of the global variable indicated by name to the given value + // raise an error if no global variable of that name exists + this.stage.globalVariables().setVar(name, value); +}; + // ProjectDialogMorph //////////////////////////////////////////////////// // ProjectDialogMorph inherits from DialogBoxMorph: