Skip to main content
Question

Can someone find the issue in my refrsh nodes code?

  • September 3, 2024
  • 1 reply
  • 34 views

ERA

Hello,

My code will refresh the first text box with the updated variable… but then it exits and throws runtime errors.

async function refreshNodesUsingVariables(updatedVariableIds) {
const nodes = Figma.currentPage.findAll();

for (const node of nodes) {
try {
let nodeUpdated = false;

  if (node.boundVariables) {
    for (const variableId of updatedVariableIds) {
      for (const [property, boundVariable] of Object.entries(node.boundVariables)) {
        if (boundVariable.id === variableId) {
        
          if (typeof node.setVariableValue === 'function') {
            node.setVariableValue(property, boundVariable); 
          } else {
            console.warn(`Function 'setVariableValue' is not available on node ${node.name}`);
          }
          nodeUpdated = true;
        }
      }
    }
  }

  if (nodeUpdated && node.type === 'TEXT' && node.fontName) {
    try {
      await figma.loadFontAsync(node.fontName);
      node.characters = node.characters; // Refresh text node
    } catch (fontError) {
      console.warn(`Error loading font for node ${node.name}:`, fontError);
    }
  }

  if (nodeUpdated) {
    console.log(`Refreshed node: ${node.name} (${node.type})`);
  }
} catch (error) {
  console.warn(`Error updating node ${node.name} of type ${node.type}:`, error);
}

}
}

Errors:
Variable ELEC_SERV_NOTE updated successfully with value: T1-Note
Function ‘setVariableValue’ is not available on node T1-Type
Refreshed node: T1-Type (TEXT)
RuntimeError: null function or function signature mismatch

How it works:
It will actually refresh the first variable but none of the other ones.

I am not a very good coder and can’t find the issue.

Thanks for your time.

This topic has been closed for replies.

1 reply

ERA
  • Author
  • 1 reply
  • September 3, 2024

So I got it to update all the fields BUT

I keep getting these darn runtimes with the WebAssembly stuff but my code has nothing to do with it.

Uncaught (in promise) RuntimeError: null function or function signature mismatch
at jsvm-cpp.wasm.br:0x358cb
at jsvm-cpp.wasm.br:0x6bac6
at jsvm-cpp.wasm.br:0x13819
at jsvm-cpp.wasm.br:0x152eb
at jsvm-cpp.wasm.br:0x3317b
at jsvm-cpp.wasm.br:0x2c352
at jsvm-cpp.wasm.br:0x2bab3

I just can’t find what’s doing it but it doesn’t break my plugin. Sigh…