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
- (::Main.workspace289.var"#1#22")()@ Local: 37
- #6 @ svg.jl:48 [inlined]
- #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
- #Drawing#5 @ svg.jl:43 [inlined]
- top-level scope @ Local: 9
My code is quite long, but it’s doing 16 times basically the same
This is my code:
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~~~