Skip to main content
Solved

Is it not possible to set a text variable to an empty string?


Alex_FG

I can set it to ’ ’ (a space), or any string with text in it, but nothing happens if the value I give it is ‘’.

Best answer by Alex_FG

I think I was setting it to null instead of ‘’. Setting it to ‘’ worked.

View original

11 replies

Alex_FG
  • Author
  • New Participant
  • 32 replies
  • September 1, 2023

nvm it’s a bug on my end 🤓


  • 1 reply
  • September 5, 2023

Hey! How did you fixed it? I have the same problem 😦


Alex_FG
  • Author
  • New Participant
  • 32 replies
  • Answer
  • September 5, 2023

I think I was setting it to null instead of ‘’. Setting it to ‘’ worked.


Martin_Mateos_Sanchez

Hello! Which ASCII character are you referring to as ‘’? Right now, I can only set it to a whitespace for the variable to appear as empty (although it isn’t, since it’s a whitespace and has a length of one)
Captura de pantalla 2024-01-06 172436


tank666
  • 4863 replies
  • January 6, 2024

You need to set it to an empty string without any character.

variable = '';

Martin_Mateos_Sanchez

Oh, is that using the API? Or is there a way using the keyboard? Because if the variable is set to a whitespace and I delete it and press intro, the variable resets to the whitespace. Similarly, if I create a new text variable, which by default is set to “String value” and I try to delete that completely and press intro, the variable resets to “String value”

So weird


tank666
  • 4863 replies
  • January 6, 2024

Only using the Plugin API. I wrote about it here:


  • 4 replies
  • May 6, 2024

Hey, I am not able to do it. Can you explain it a bit more ? How do I set a string’s value as null


tank666
  • 4863 replies
  • May 6, 2024

You cannot set null as a value for a string variable. Instead of null, you must specify an empty string.

variable.setValueForMode(modeId, '')

Joseph_Kaguri

Hi, could you share the full code that you added on Run plugin API to set a String variable empty?


tank666
  • 4863 replies
  • November 4, 2024
const collection = figma.variables.createVariableCollection('New collection'),
    modeId = collection.defaultModeId,
    variable = figma.variables.createVariable('New string variable', collection, 'STRING');

variable.setValueForMode(modeId, '');

This code will create a new collection with a variable with an empty value.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings