Changing font variable


#1

Can anyone suggest how to change the content of a font in script?

I have a text field called word which I need to change on a button press (const word = symbol.nodes.word;)

Thank you


#2

Hello @stephen.bedser
What you can do about it is have a text node on your hierarchy and do a code like this:

symbol.nodes.btn.on("pointerup", ()=>{
    symbol.nodes.fontRoboto.font(symbol.mediaFiles.Blackout_ttf)
});

In this way your text’s font will change as expected. You can do some kinda of array for this if you want so with all your mediaFiles fonts.

att, Higão.


#3

Thanks higor :slight_smile:


#4

@higor …looking at that, I actually want to change the text contained… so if the word displayed was say “one” I want the same text container to be changed to say “two”…can I use variables? Apologies if I’m not explaining myself right ! :slight_smile:


#5

No worries, maybe I understand it wrong. All you have to do then is change a little part of your code, like this:

symbol.nodes.btn.on("pointerup", ()=>{
    symbol.nodes.fontRoboto.text("text what you want to change");
});

Try this one and tell me.

Att, Higão;


#6

Wonderful, thanks for your help @higor!


#7

Nice one @higor - super helpful as always.


#8

Thank you @james.wright :smiley:

I try…

att, Higão.