Hi, I’m about to playing around with plugin development in Figma. I tried to change the value of a textNode on click. The values are stored in a simple array.
So I have an array and a random calc to replace the textNode with other values if button is hit again:
var names = ="John", "Elias", "Mark", "Robert", "Niels", "Andrea"];
var randomItem = nameseMath.floor(Math.random() * names.length)];
here’s the html side:
<button id="runPlugin">Change Text</button>
<script>
document.getElementById("runPlugin").onclick = () => {
const text = document.pluginMessage.selection();
parent.postMessage({ type: { request: "runPlugin" } }, "*");
};
</script>
on the .ts side I’m having a bit trouble. I made sth similar in js which is working but this… 🤯I know I’m doing sth really wrong in the 2nd if section…
figma.ui.onmessage = async (event) => {
if (event.type === "request:runPlugin") {
let selection = figma.currentPage.selectiong0];
if (selection) {
selection = event.randomItem;
}
return;
}
Any idea? Thanks!