# Unexpected ERROR: UndefVarError: a not defined

**URL:** <https://discourse.julialang.org/t/unexpected-error-undefvarerror-a-not-defined/60379>\
**Category:** Performance\
**Created:** [May 1, 2021, 12:51pm UTC](https://discourse.julialang.org/t/unexpected-error-undefvarerror-a-not-defined/60379 "2021-05-01T12:51:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![M0ran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/m0ran/32/23529_2.png) [@M0ran](https://discourse.julialang.org/u/M0ran)\
**Post date:** [May 1, 2021, 12:51pm UTC](https://discourse.julialang.org/t/unexpected-error-undefvarerror-a-not-defined/60379/1 "2021-05-01T12:51:14Z")

</div>

Hey, I’m new to Julia and I have to program the game “paper soccer” for school. It’s almost finished, but now I got this “UndefVarError: a not defined” error. Since I’ve always adapted my code step by step, I really don’t know where this is comming from. Especially because “a” is the first variable I’ve defined in my code. This is what the error looks like:

UndefVarError: a not defined

1. (::Main.workspace289.var"#1#22")()@ _[Local: 37](http://localhost:1234/edit?id=4bd8e2e0-aa76-11eb-0ae7-3177be6886a9#)_
2. **#6** @ _svg.jl:48_ [inlined]
3. **#svg#40** (::Base.Iterators.Pairs{Symbol,String,Tuple{Symbol,Symbol,Symbol},NamedTuple{(:xmlns, :width, :height),Tuple{String,String,String}}}, ::typeof(NativeSVG.svg), ::NativeSVG.var"#6#7"{Main.workspace289.var"#1#22"}, ::Base.GenericIOBuffer{Array{UInt8,1}})@ _svg.jl:94_
4. **#Drawing#5** @ _svg.jl:43_ [inlined]
5. **top-level scope** @ _[Local: 9](http://localhost:1234/edit?id=4bd8e2e0-aa76-11eb-0ae7-3177be6886a9#)_

My code is quite long, but it’s doing 16 times basically the same  
This is my code:

```julia

c = tuple(a, b)

spel = []

md"""
keuze: $(@bind keuze html"<input type=string>")\
"""
function input()
	if length(keuze) == 5
		push!(spel, keuze)
	end
end

begin
	input()
	C = []
	E = []
	T = []
	l = 2
	m = 10
	n = 8
		Drawing(width = join(["$(l*(n+2))", "cm"]), height = join(["$(l*(m+4))", "cm"])) do
			#bovenste deel van het bord
			g(fill = "none", stroke = "black", stroke_width = "0.5") do
				line(x1 = join(["$(((n/2))*l)", "cm"]), y1 = join(["$l", "cm"]), x2 = join(["$(((n/2)+2)*l)", "cm"]), y2 = join(["$l", "cm"]))
				for i in 0:2
					line(x1 = join(["$(((n/2)+i)*l)", "cm"]), y1 = join(["$l", "cm"]), x2 = join(["$(((n/2)+i)*l)", "cm"]), y2 = join(["$(2*l)", "cm"]))
				end
			end
			#middendeel van het bord
			for j in 1:m+1
				g(fill = "none", stroke = "black", stroke_width = "0.5") do
					line(x1 = join(["$l", "cm"]), y1 = join(["$((j+1)*l)", "cm"]), x2 = join(["$(l*(n+1))", "cm"]), y2 = join(["$((j+1)*l)", "cm"]))
				end
			end
			for j in 1:n+1
				g(fill = "none", stroke = "black", stroke_width = "0.5") do
					line(x1 = join(["$(l*j)", "cm"]), y1 = join(["$(2*l)", "cm"]), x2 = join(["$(l*j)", "cm"]), y2 = join(["$(l*(m+2))", "cm"]))
				end
			end
			#onderste deel van het bord
			g(fill = "none", stroke = "black", stroke_width = "0.5") do
				line(x1 = join(["$((n/2)*l)", "cm"]), y1 = join(["$((m+3)*l)", "cm"]), x2 = join(["$(((n/2)+2)*l)", "cm"]), y2 = join(["$((m+3)*l)", "cm"]))
				for i in 0:2
					line(x1 = join(["$(((n/2)+i)*l)", "cm"]), y1 = join(["$((m+2)*l)", "cm"]), x2 = join(["$(((n/2)+i)*l)", "cm"]), y2 = join(["$((m+3)*l)", "cm"]))
				end
			end
		if length(spel) ≥ 1
			for i in 1:length(spel) 
				if a ≥ -1 && a ≤ 11 && b ≥ 0 && b ≤ 8
					if spel[i] == "zet1x"
						p = a
						q = b+1
						d = tuple(p, q)
						c = tuple(a, b)
						f = tuple(c, d)
						if f ∈ E || f ∈ T
							println("This won't work, choose another move")
						else
							g(fill = "none", stroke = "red", stroke_width = "2") do
								line(x1 = join(["$((b+1)*l)", "cm"]), y1 = join(["$((a+2)*l)", "cm"]), x2 = join(["$((b+2)*l)", "cm"]), y2 = join(["$((a+2)*l)", "cm"]))
							end
							push!(C, c)
							e = tuple(c, d)
							push!(E, e)
							t = reverse(e)
							push!(T, t)
							b = b+1
						end
						
					elseif spel[i] == "zet2x"
						p = a
						q = b-1
						d = tuple(p, q)
						c = tuple(a, b)
						f = tuple(c, d)
						if f ∈ E || f ∈ T
							println("This won't work, choose another move")
						else
							g(fill = "none", stroke = "red", stroke_width = "2") do
								line(x1 = join(["$((b+1)*l)", "cm"]), y1 = join(["$((a+2)*l)", "cm"]), x2 = join(["$(b*l)", "cm"]), y2 = join(["$((a+2)*l)", "cm"]))
							end
							push!(C, c)
							e = tuple(c, d)
							push!(E, e)
							t = reverse(e)
							push!(T, t)
							b = b-1
						end
						
					elseif spel[i] == "zet3x"
						p = a-1
						q = b
						d = tuple(p, q)
						c = tuple(a, b)
						f = tuple(C, d)
						if f ∈ E || f ∈ T
							println("This won't work, choose another move")
						else
							g(fill = "none", stroke = "red", stroke_width = "2") do
								line(x1 = join(["$((b+1)*l)", "cm"]), y1 = join(["$((a+2)*l)", "cm"]), x2 = join(["$((b+1)*l)", "cm"]), y2 = join(["$((a+3)*l)", "cm"]))
							end
							push!(C, c)
							e = tuple(c, d)
							push!(E, e)
							t = reverse(e)
							push!(T, t)
							a = a+1
						end
						
					elseif spel[i] == "zet4x"
						p = a+1
						q = b
						d = tuple(p, q)
						c = tuple(a, b)
						f = tuple(c, d)
						if f ∈ E || f ∈ T
							println("This won't work, choose another move")
						else
							g(fill = "none", stroke = "red", stroke_width = "2") do
								line(x1 = join(["$((b+1)*l)", "cm"]), y1 = join(["$((a+2)*l)", "cm"]), x2 = join(["$((b+1)*l)", "cm"]), y2 = join(["$((a+1)*l)", "cm"]))
							end
							push!(C, c)
							e = tuple(c, d)
							push!(E, e)
							t = reverse(e)
							push!(T, t)
							a = a-1
						end
						
					elseif spel[i] == "zet5x"
						p = a+1
						q = b+1
						d = tuple(p, q)
						c = tuple(a, b)
						f = tuple(c, d)
						if f ∈ E || f ∈ T
							println("This won't work, choose another move")
						else
							g(fill = "none", stroke = "red", stroke_width = "2") do
								line(x1 = join(["$((b+1)*l)", "cm"]), y1 = join(["$((a+2)*l)", "cm"]), x2 = join(["$((b+2)*l)", "cm"]), y2 = join(["$((a+3)*l)", "cm"]))
							end
							push!(C, c)
							e = tuple(c, d)
							push!(E, e)
							t = reverse(e)
							push!(T, t)
							a = a+1
							b = b+1
						end
						
					elseif spel[i] == "zet6x"
						p = a-1
						q = b+1
						d = tuple(p, q)
						c = tuple(a, b)
						f = tuple(c, d)
						if f ∈ E || f ∈ T
							println("This won't work, choose another move")
						else
							g(fill = "none", stroke = "red", stroke_width = "2") do
								line(x1 = join(["$((b+1)*l)", "cm"]), y1 = join(["$((a+2)*l)", "cm"]), x2 = join(["$((b+2)*l)", "cm"]), y2 = join(["$((a+1)*l)", "cm"]))
							end
							push!(C, c)
							e = tuple(c, d)
							push!(E, e)
							t = reverse(e)
							push!(T, t)
							a = a-1
							b = b+1
						end
						
					elseif spel[i] == "zet7x"
						p = a+1
						q = b-1
						d = tuple(p, q)
						c = tuple(a, b)
						f = tuple(c, d)
						if f ∈ E || f ∈ T
							println("This won't work, choose another move")
						else
							g(fill = "none", stroke = "red", stroke_width = "2") do
								line(x1 = join(["$((b+1)*l)", "cm"]), y1 = join(["$((a+2)*l)", "cm"]), x2 = join(["$(b*l)", "cm"]), y2 = join(["$((a+3)*l)", "cm"]))
							end
							push!(C, c)
							e = tuple(c, d)
							push!(E, e)
							t = reverse(e)
							push!(T, t)
							a = a+1
							b = b-1
						end
						
					elseif spel[i] == "zet8x"
						p = a-1
						q = b-1
						d = tuple(p, q)
						c = tuple(a, b)
						f = tuple(c, d)
						if f ∈ E || f ∈ T
							println("This won't work, choose another move")
						else
							g(fill = "none", stroke = "red", stroke_width = "2") do
								line(x1 = join(["$((b+1)*l)", "cm"]), y1 = join(["$((a+2)*l)", "cm"]), x2 = join(["$(b*l)", "cm"]), y2 = join(["$((a+1)*l)", "cm"]))
							end
							push!(C, c)
							e = tuple(c, d)
							push!(E, e)
							t = reverse(e)
							push(T, t)
							a = a-1
							b = b-1
						end
							
					elseif spel[i] == "zet1y"
						p = a
						q = b+1
						d = tuple(p, q)
						c = tuple(a, b)
						f = tuple(c, d)
						if f ∈ E || f ∈ T
							println("This won't work, choose another move")
						else
							g(fill = "none", stroke = "green", stroke_width = "2") do
								line(x1 = join(["$((b+1)*l)", "cm"]), y1 = join(["$((a+2)*l)", "cm"]), x2 = join(["$((b+2)*l)", "cm"]), y2 = join(["$((a+2)*l)", "cm"]))
							end
							push!(C, c)
							e = tuple(c, d)
							push!(E, e)
							t = reverse(e)
							push!(T, t)
							b = b+1
						end
						
					elseif spel[i] == "zet2y"
						p = a
						q = b-1
						d = tuple(p, q)
						c = tuple(a, b)
						f = tuple(c, d)
						if f ∈ E || f ∈ T
							println("This won't work, choose another move")
						else
							g(fill = "none", stroke = "green", stroke_width = "2") do
								line(x1 = join(["$((b+1)*l)", "cm"]), y1 = join(["$((a+2)*l)", "cm"]), x2 = join(["$(b*l)", "cm"]), y2 = join(["$((a+2)*l)", "cm"]))
							end
							push!(C, c)
							e = tuple(c, d)
							push!(E, e)
							t = reverse(e)
							push!(T, t)
							b = b-1
						end
						
					elseif spel[i] == "zet3y"
						p = a-1
						q = b
						d = tuple(p, q)
						c = tuple(a, b)
						f = tuple(c, d)
						if f ∈ E || f ∈ T
							println("This won't work, choose another move")
						else
							g(fill = "none", stroke = "green", stroke_width = "2") do
								line(x1 = join(["$((b+1)*l)", "cm"]), y1 = join(["$((a+2)*l)", "cm"]), x2 = join(["$((b+1)*l)", "cm"]), y2 = join(["$((a+3)*l)", "cm"]))
							end
							push!(C, c)
							e = tuple(c, d)
							push!(E, d)
							t = reverse(e)
							push!(T, t)
							a = a+1
						end
						
					elseif spel[i] == "zet4y"
						p = a+1
						q = b
						d = tuple(p, q)
						c = tuple(a, b)
						f = tuple(c, d)
						if f ∈ E || f ∈ T
							println("This won't work, choose another move")
						else
							g(fill = "none", stroke = "green", stroke_width = "2") do
								line(x1 = join(["$((b+1)*l)", "cm"]), y1 = join(["$((a+2)*l)", "cm"]), x2 = join(["$((b+1)*l)", "cm"]), y2 = join(["$((a+1)*l)", "cm"]))
							end
							push!(C, c)
							e = tuple(c, d)
							push!(E, e)
							t = reverse(e)
							push!(T, t)
							a = a-1
						end
						
					elseif spel[i] == "zet5y"
						p = a+1
						q = b+1
						d = tuple(p, q)
						c = tuple(a, b)
						f = tuple(c, d)
						if f ∈ E || f ∈ T
							println("This won't work, choose another move")
						else
							g(fill = "none", stroke = "green", stroke_width = "2") do
								line(x1 = join(["$((b+1)*l)", "cm"]), y1 = join(["$((a+2)*l)", "cm"]), x2 = join(["$((b+2)*l)", "cm"]), y2 = join(["$((a+3)*l)", "cm"]))
							end
							push!(C, c)
							e = tuple(c, d)
							push!(E, e)
							t = reverse(e)
							push!(T, t)
							a = a+1
							b = b+1
						end
						
					elseif spel[i] == "zet6y"
						p = a-1
						q = b+1
						d = tuple(p, q)
						c = tuple(a, b)
						f = tuple(c, d)
						if f ∈ E || f ∈ T
							println("This won't work, choose another move")
						else
							g(fill = "none", stroke = "green", stroke_width = "2") do
								line(x1 = join(["$((b+1)*l)", "cm"]), y1 = join(["$((a+2)*l)", "cm"]), x2 = join(["$((b+2)*l)", "cm"]), y2 = join(["$((a+1)*l)", "cm"]))
							end
							push!(C, c)
							e = tuple(c, d)
							push!(E, e)
							t = reverse(e)
							push(T, t)
							a = a-1
							b = b+1
						end
						
					elseif spel[i] == "zet7y"
						p = a+1
						q = b-1
						d = tuple(p, q)
						c = tuple(a, b)
						f = tuple(c, d)
						if f ∈ E || f ∈ T
							println("This won't work, choose another move")
						else
							g(fill = "none", stroke = "green", stroke_width = "2") do
								line(x1 = join(["$((b+1)*l)", "cm"]), y1 = join(["$((a+2)*l)", "cm"]), x2 = join(["$(b*l)", "cm"]), y2 = join(["$((a+3)*l)", "cm"]))
							end
							push!(C, c)
							e = tuple(c, d)
							push!(E, e)
							t = reverse(e)
							push!(T, t)
							a = a+1
							b = b-1
						end
							
					elseif spel[i] == "zet8y"
						p = a-1
						q = b-1
						d = tuple(p, q)
						c = tuple(a, b)
						f = tuple(c, d)
						if f ∈ E || f ∈ T
							println("This won't work, choose another move")
						else
							g(fill = "none", stroke = "green", stroke_width = "2") do
								line(x1 = join(["$((b+1)*l)", "cm"]), y1 = join(["$((a+2)*l)", "cm"]), x2 = join(["$(b*l)", "cm"]), y2 = join(["$((a+1)*l)", "cm"]))
							end
							push!(C, c)
							e = tuple(c, d)
							push!(E, e)
							t = reverse(e)
							push!(T, t)
							a = a-1
							b = b-1
						end
					end
				end
				if (a, b) ∈ C
					println("De speler die aan zet is, mag nog een zet doen")
				end
				if b == 0 || b == 8
					println("Het spel is gedaan")
					for i in 1:length(C)
						pop!(C)
					end
					for i in 1:length(spel)
					pop!(spel)
					end
					(a, b) = (5, 4)
				end
				for i in 3:5
					if (a, b) == (-1, i) || (a, b) == (11, i)
						println("Het spel is gedaan")
						for i in 1:length(C)
							pop!(C)
						end
						for i in 1:length(spel)
							pop!(spel)
						end
						(a, b) = (5, 4)
					end
				end
				for i in [0, 1, 2, 6, 7, 8]
					if (a, b) == (0, i) || (a, b) == (10, i)
						println("Het spel is gedaan")
						for i in 1:length(C)
							pop!(C)
						end
						for i in 1:length(spel)
							pop!(spel)
						end
						(a, b) = (5, 4)
					end
				end	
			end
		end
	end
end~~~
```

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [May 1, 2021, 1:14pm UTC](https://discourse.julialang.org/t/unexpected-error-undefvarerror-a-not-defined/60379/2 "2021-05-01T13:14:17Z")

</div>

Welcome to our community! 🎊

We will need the code to be able to help more. However, I see that the problem happened at `Main.workspace289` are you using `Pluto.jl` or something that wraps your code in automatically generated modules?

---

<div class="post-metadata">

**Author:** ![M0ran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/m0ran/32/23529_2.png) [@M0ran](https://discourse.julialang.org/u/M0ran)\
**Post date:** [May 1, 2021, 2:51pm UTC](https://discourse.julialang.org/t/unexpected-error-undefvarerror-a-not-defined/60379/3 "2021-05-01T14:51:56Z")

</div>

Thanks for your answer! I am indeed using Pluto.jl to write my code + NativeSVG if that’s necessary information. I will try to upload my code.

---

<div class="post-metadata">

**Author:** ![M0ran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/m0ran/32/23529_2.png) [@M0ran](https://discourse.julialang.org/u/M0ran)\
**Post date:** [May 1, 2021, 3:07pm UTC](https://discourse.julialang.org/t/unexpected-error-undefvarerror-a-not-defined/60379/4 "2021-05-01T15:07:10Z")

</div>

My code might look a bit unclear, so here’s where I think something might have gone wrong.

```nohighlight
			for i in 1:length(spel) 
				if a ≥ -1 && a ≤ 11 && b ≥ 0 && b ≤ 8
					if spel[i] == "zet1x"
						p = a
						q = b+1
						d = tuple(p, q)
						c = tuple(a, b)
						f = tuple(c, d)
						if f ∈ E || f ∈ T
							println("This won't work, choose another move")
						else
							g(fill = "none", stroke = "red", stroke_width = "2") do
								line(x1 = join(["$((b+1)*l)", "cm"]), y1 = join(["$((a+2)*l)", "cm"]), x2 = join(["$((b+2)*l)", "cm"]), y2 = join(["$((a+2)*l)", "cm"]))
							end
							push!(C, c)
							e = tuple(c, d)
							push!(E, e)
							t = reverse(e)
							push!(T, t)
							b = b+1
						end

```

For your interest: Previously, I defined:  
(a, b) = (5, 4)  
C =   
E =   
T =   
C, E and T are empty arrays  
There’s a variable “keuze” that takes a string “zet1x”. The function “input” takes the value of “keuze” and puts it in an array “spel”. My code is always evaluating that array “spel”. I defined those arrays C, E and T to save the coordinates we’ve passed, this is to be able to add the rules to the game. The weird thing is that my code used to work untill I added the array T. So without T and t, my code used to work.

---

<div class="post-metadata">

**Author:** ![M0ran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/m0ran/32/23529_2.png) [@M0ran](https://discourse.julialang.org/u/M0ran)\
**Post date:** [May 1, 2021, 3:44pm UTC](https://discourse.julialang.org/t/unexpected-error-undefvarerror-a-not-defined/60379/5 "2021-05-01T15:44:23Z")

</div>

To add some extra information:  
If I define my a and b at the beginning of my code, I get the error. Like I did here:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/0/408cea96c613d458a9b75db2a7d0bf324da7a36e.png)

---

<div class="post-metadata">

**Author:** ![M0ran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/m0ran/32/23529_2.png) [@M0ran](https://discourse.julialang.org/u/M0ran)\
**Post date:** [May 1, 2021, 3:45pm UTC](https://discourse.julialang.org/t/unexpected-error-undefvarerror-a-not-defined/60379/6 "2021-05-01T15:45:24Z")

</div>

While if I define my a and b later in my code, I don’t get the error. Even though it’s on the same Hight. Like I did here:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/b/4bc02316e338ea8a2763e69135e04b93e505f166.png)

---

<div class="post-metadata">

**Author:** ![bashonubuntu](https://avatars.discourse-cdn.com/v4/letter/b/f19dbf/32.png) [@bashonubuntu](https://discourse.julialang.org/u/bashonubuntu)\
**Post date:** [May 1, 2021, 4:37pm UTC](https://discourse.julialang.org/t/unexpected-error-undefvarerror-a-not-defined/60379/7 "2021-05-01T16:37:34Z")

</div>

I think the first step here would be to paste your code in a way we can run in our machines. I realize this could be a bit more borhersome, but it will allow us to help you more quickly (and, we really want to since we’re a nice community! 🙂 )

For example

```julia
your code should be inside this 

```

Some other useful guidelines on how to post code, use discourse most efficiently etc. are also given here:

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![M0ran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/m0ran/32/23529_2.png) [@M0ran](https://discourse.julialang.org/u/M0ran)\
**Post date:** [May 1, 2021, 7:07pm UTC](https://discourse.julialang.org/t/unexpected-error-undefvarerror-a-not-defined/60379/8 "2021-05-01T19:07:14Z")

</div>

Thanks for your advice, I hope it’s better now.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [May 1, 2021, 7:40pm UTC](https://discourse.julialang.org/t/unexpected-error-undefvarerror-a-not-defined/60379/9 "2021-05-01T19:40:52Z")

</div>

Looks like a scope problem. Try to add `global a` just before `a` is first used.

(We still cannot copy/paste and run the code)
