# Why does the interpreter expect my variable font to be global? (Solved)

**URL:** <https://forum.inductiveautomation.com/t/why-does-the-interpreter-expect-my-variable-font-to-be-global-solved/94454>\
**Category:** Ignition\
**Tags:** vision, scripting\
**Created:** [August 9, 2024, 11:21pm UTC](https://forum.inductiveautomation.com/t/why-does-the-interpreter-expect-my-variable-font-to-be-global-solved/94454 "2024-08-09T23:21:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anise\_Bamford](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/anise_bamford/32/66252_2.png) [@Anise\_Bamford](https://forum.inductiveautomation.com/u/Anise_Bamford)\
**Post date:** [August 9, 2024, 11:21pm UTC](https://forum.inductiveautomation.com/t/why-does-the-interpreter-expect-my-variable-font-to-be-global-solved/94454/1 "2024-08-09T23:21:01Z")

</div>

I'm trying to implement style generation for vision projects by using datasets. I have a dataset that has foreground, background, bold, and italics values for 4 different urgency levels. Foreground and background are both colors, and bold and italics are both boolean. I can get the colors to apply, but when I try to update the font, I run into trouble. Here's what I'm trying:

```python
def setStyle(component, errorLevel, styles = None):
	if not styles:
	  styles = system.tag.readBlocking("[default]styles")[0].value
	
	def getColumnByName(name):
		return styles.getColumnNames().index(name)
	
	def getStyleValue(name):
		return styles.getValueAt(errorLevel, getColumnByName(name))
		
	def getUpdatedFontValue(font):
		bold = getStyleValue("bold") * font.BOLD
    	italic = getStyleValue("italics") * font.ITALIC
    	return font.derive(bold | italic)

	component.foreground = getStyleValue("foreground")
	component.background = getStyleValue("background")
	component.font = getUpdatedFontValue(component.font)

```

When I run this code, I get the following error:

```python
Traceback (most recent call last):
  File "<event:propertyChange>", line 1, in <module>
  File "<module:setStyle>", line 13, in setStyle
NameError: global name 'font' is not defined

```

I think `font` should be defined in the function definition, what am I doing wrong?

---

<div class="post-metadata">

**Author:** ![Anise\_Bamford](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/anise_bamford/32/66252_2.png) [@Anise\_Bamford](https://forum.inductiveautomation.com/u/Anise_Bamford)\
**Post date:** [August 10, 2024, 12:00am UTC](https://forum.inductiveautomation.com/t/why-does-the-interpreter-expect-my-variable-font-to-be-global-solved/94454/2 "2024-08-10T00:00:55Z")

</div>

I figured out that the problem was that I had a mix of spaces and tabs.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 10, 2024, 12:04am UTC](https://forum.inductiveautomation.com/t/why-does-the-interpreter-expect-my-variable-font-to-be-global-solved/94454/3 "2024-08-10T00:04:48Z")

</div>

> [@Anise\_Bamford](#):
>
> ```python
> styles = system.tag.readBlocking("[default]styles")[0].value
> 
> ```

All other things aside (I would strongly recommend the use of the style customizer over scripting everything) -- this is a _really_ bad idea. `propertyChange` events are fired constantly, and on the event dispatch thread. You should be using a tag binding (guaranteed asynchronous, off the EDT) to bring in your dataset of styles.

---

<div class="post-metadata">

**Author:** ![Anise\_Bamford](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/anise_bamford/32/66252_2.png) [@Anise\_Bamford](https://forum.inductiveautomation.com/u/Anise_Bamford)\
**Post date:** [August 10, 2024, 12:17am UTC](https://forum.inductiveautomation.com/t/why-does-the-interpreter-expect-my-variable-font-to-be-global-solved/94454/4 "2024-08-10T00:17:19Z")

</div>

> [@paul-griffith](#):
>
> I would strongly recommend the use of the style customizer over scripting everything

I understand. I'm trying to learn how to do scripting, and for me, it's useful to have problems to solve, so I invent them. In this case, the problem I invented is that I have a user who is colorblind, so they need a different color palette when they're logged in.
