From 6622687984eec3b2e2eb78066c21734ee3d0af18 Mon Sep 17 00:00:00 2001 From: LilyMakesThings <127533508+LilyMakesThings@users.noreply.github.com> Date: Mon, 12 Feb 2024 14:19:55 +0000 Subject: [PATCH] Fix field variable default value --- core/field_variable.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/field_variable.js b/core/field_variable.js index c188482bd6..bf23195f8e 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -106,9 +106,14 @@ Blockly.FieldVariable.prototype.initModel = function() { return; // Initialization already happened. } this.workspace_ = this.sourceBlock_.workspace; + + var variables = this.workspace_.getVariablesOfType(this.defaultType_); + variables = variables.sort(Blockly.VariableModel.compareByName); + var variable = Blockly.Variables.getVariable(this.workspace_, this.defaultVariableName, null, this.defaultType_); + // Initialize this field if it's in a broadcast block in the flyout - var variable = this.initFlyoutBroadcast_(this.workspace_); - if (!variable) { + if (this.workspace_.isFlyout && !variable && variables.length > 0) variable = variables[0]; + if (variables.length < 1) { var variable = Blockly.Variables.getOrCreateVariablePackage( this.workspace_, null, this.defaultVariableName, this.defaultType_); }