Posted 18 April 2013 - 08:08 AM
Hey guys, i've been working on an portal - like adv. map.
It's not much, but i made a little quiz in it to activate some faithplates when solved,
there're only 3 questions and 2 buttons and a life counter.
I just wanted to show you the code and ask if the code i wrote is good or not, and if it's not really good,
i want to know what i could do better, because I'm kind of new to Lua. :)/>
Here's the code:
I really want to here your suggestions. ^_^/>
Sincerely,
Skampi.
Btw, if you're interested in helping / testing, write me. :)/>
It's not much, but i made a little quiz in it to activate some faithplates when solved,
there're only 3 questions and 2 buttons and a life counter.
I just wanted to show you the code and ask if the code i wrote is good or not, and if it's not really good,
i want to know what i could do better, because I'm kind of new to Lua. :)/>
Here's the code:
m = peripheral.wrap("back")
function lifes(B)/>/>/>
if b == "wrong" then
m.setCursorPos(40, 10)
m.setTextColor(colors.black)
m.write("Lifes : "..c)
c = c - 1
m.setTextColor(colors.white)
m.setCursorPos(40, 10)
m.write("Lifes : "..c)
sleep(2)
else
m.setCursorPos(40, 10)
m.setTextColor(colors.white)
m.write("Lifes : "..c)
end
function buttons()
m.setTextScale(1)
m.setCursorPos(15, 10)
m.write("A")
m.setCursorPos(36, 10)
m.write("B")
end
function Antwort(x, y)
if x == 1 then
m.setCursorPos(15, 10)
m.write(y)
elseif x == 2 then
m.setCursorPos(36, 10)
m.write(y)
end
end
end
--Question 1
c = 3
lifes("right")
m.setCursorPos(3, 2)
m.write(" Which Soul Shard tier is needed to let")
m.setCursorPos(3, 4)
m.write(" mobs spawn in other dimensions?")
Antwort(1, "4")
Antwort(2, "5")
a = 1
z = 1
while a == 1 do
if rs.getInput("right") then
m.setCursorPos(15, 10)
m.setTextColor(colors.lime)
m.write("4")
a = 0
sleep(2)
else
sleep(0.5)
end
if rs.getInput("left") and z == 1 then
m.setCursorPos(36, 10)
m.setTextColor(colors.red)
m.write("5")
lifes("wrong")
z = 0
else
sleep(0.5)
end
end
--Question 2
m.setTextColor(colors.white)
shell.run("monitor back clear")
lifes("right")
m.setCursorPos(3, 2)
m.write("How many marble blocks are theoretically")
m.setCursorPos(3, 4)
m.write("needed to make 1 Marble Brick?")
Antwort(1, "2")
Antwort(2, "1")
k = 1
l = 1
while k == 1 do
if rs.getInput("left") then
m.setCursorPos(36, 10)
m.setTextColor(colors.lime)
m.write("1")
k = 0
sleep(2)
else
sleep(0.5)
end
if rs.getInput("right") and l == 1 then
m.setCursorPos(15, 10)
m.setTextColor(colors.red)
m.write("2")
lifes("wrong")
l = 0
else
sleep(0.5)
end
end
--Question 3
m.setTextColor(colors.white)
shell.run("monitor back clear")
lifes("right")
m.setCursorPos(3, 2)
m.write("Is it possible to change obsidian with ")
m.setCursorPos(3, 4)
m.write("the Wand of equal Trade?")
Antwort(1, "No")
Antwort(2, "Yes")
n = 1
o = 1
while n == 1 do
if rs.getInput("left") then
m.setCursorPos(36, 10)
m.setTextColor(colors.lime)
m.write("Yes")
n = 0
sleep(2)
else
sleep(0.5)
end
if rs.getInput("right") and o == 1 then
m.setCursorPos(15, 10)
m.setTextColor(colors.red)
m.write("No")
lifes("wrong")
o = 0
else
sleep(0.5)
end
end
--Ende
if c == 0 then
shell.run("monitor back clear")
m.setCursorPos(12, 3)
m.setTextScale(2)
m.setTextColor(colors.red)
m.write("FAIL")
m.setCursorPos(3, 4)
m.write("Extra Chamber enabled")
elseif c > 0 then
shell.run("monitor back clear")
m.setCursorPos(10, 3)
m.setTextScale(2)
m.setTextColor(colors.lime)
m.write("Success")
m.setCursorPos(3, 4)
m.write("Faith-Plates enabled")
rs.setOutput("front", true)
end
I really want to here your suggestions. ^_^/>
Sincerely,
Skampi.
Btw, if you're interested in helping / testing, write me. :)/>