Skip to content

Commit

Permalink
Fix field variable default value
Browse files Browse the repository at this point in the history
  • Loading branch information
LilyMakesThings authored Feb 12, 2024
1 parent 3c4fce8 commit 6622687
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions core/field_variable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}
Expand Down

0 comments on commit 6622687

Please sign in to comment.