Skip to content

Handling Fields that Reference Variables #2531

@BeksOmega

Description

@BeksOmega

Problem statement

Currently there is a referencesVariables function that is supposed to tell blockly whether a field references variables. But the way blockly gets the variables after it knows they are being referenced is pretty inflexible.

Blockly.Block.prototype.getVars = function() {
  var vars = [];
  for (var i = 0, input; input = this.inputList[i]; i++) {
    for (var j = 0, field; field = input.fieldRow[j]; j++) {
      if (field.referencesVariables()) {
        vars.push(field.getValue());
      }
    }
  }
  return vars;
};

This expects the value of the field to be a variable name, but this is not necessarily true of custom fields. The value could be two variable names, or a variable name and a const, really anything.

Proposals

  1. Add a getReferencedVariables() function that fields could override instead of referencesVariables().
  2. Remove referencesVariables(), instead add a type property to fields, and then have getVars check if the field is a variable field before calling getValue(). This means only variable fields would be allowed to reference variables.

Additional Information

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExternal contributions actively solicitedissue: docsDescribes missing or incorrect documentation

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions