Posted 08 May 2013 - 11:25 PM
"[Lua]Question about my code.
So I've coded a touch control program using an advanced monitor. I've got it functioning, but im just wondering why I can't have two different commands on the same y line. For example if I have this line of code:
if (xPos = 1 or 2) and (yPos = 10) then
–do something here–
Then this one:
if (xPos = 5 or 6) and (yPos = 10) then
–do something here–
the second line of code doesn't work. the function I call for on the first line of code is always what happens even if im clicking where the second should kick in.
to work around it I've just separated them to different y lines but is there another way? it doesn't look like I want it at the moment. I was thinking I may need to use buttons instead, but I need some guidance on where to go for that. Anyways here is the code so far so maybe you can fix it.
and
Thanks!
So I've coded a touch control program using an advanced monitor. I've got it functioning, but im just wondering why I can't have two different commands on the same y line. For example if I have this line of code:
if (xPos = 1 or 2) and (yPos = 10) then
–do something here–
Then this one:
if (xPos = 5 or 6) and (yPos = 10) then
–do something here–
the second line of code doesn't work. the function I call for on the first line of code is always what happens even if im clicking where the second should kick in.
to work around it I've just separated them to different y lines but is there another way? it doesn't look like I want it at the moment. I was thinking I may need to use buttons instead, but I need some guidance on where to go for that. Anyways here is the code so far so maybe you can fix it.
--Control for Wireless Turtle: Trikk 2013
rednet.open("top") --You can use top, left, right, or back for the wireless modem.
local m = peripheral.wrap("right") --Again, top right left or back. This time for the monitor.
function draw() --This is the code to put text on the attached monitor.
m.clear()
m.setTextScale(0.5)
m.setCursorPos(7,1)
m.setTextColor(16)
m.write("UP")
m.setCursorPos(6,10)
m.setTextColor(16)
m.write("DOWN")
m.setCursorPos(1,5)
m.setTextColor(2048)
m.write("LEFT")
m.setCursorPos(11,6)
m.setTextColor(2048)
m.write("RIGHT")
m.setCursorPos(5,3)
m.setTextColor(16384)
m.write("FORWARD")
m.setCursorPos(6,8)
m.setTextColor(16384)
m.write("BACK")
end
draw()
while true do --This is the code to tell if there has been a specific position on the monitor clicked.
event, side, xPos, yPos = os.pullEvent("monitor_touch") --Additionally different locations call for different functions.
if (xPos == 7 or 8) and (yPos == 1) then
rednet.broadcast("u")
elseif (xPos == 6 or 7 or 8 or 9) and (yPos == 10) then
rednet.broadcast("d")
elseif (xPos == 1 or 2 or 3 or 4) and (yPos == 5) then
rednet.broadcast("l")
elseif (xPos == 11 or 12 or 13 or 14 or 15) and (yPos == 6) then
rednet.broadcast("r")
elseif (xPos == 5 or 6 or 7 or 8 or 9 or 10 or 11) and (yPos == 3) then
rednet.broadcast("f")
elseif (xPos == 6 or 7 or 8 or 8) and (yPos == 8) then
rednet.broadcast ("b")
end
end
and
--Wireless Turtle Code : Trikk 2013
rednet.open("right") --Open the modem on the turtle.
function forward() --Forward function
detect = turtle.detect()
if detect == true then
dig()
end
turtle.forward()
end
function back() --Back function
turtle.back()
end
function right() --Right function
turtle.turnRight()
end
function left() --Left function
turtle.turnLeft()
end
function up() --Up function
detect = turtle.detectUp()
if detect == true then
digU()
end
turtle.up()
end
function down() --Down function
detect = turtle.detectDown()
if detect == true then
digD()
end
turtle.down()
end
function dig() --Dig function
turtle.dig()
sleep(0.50)
end
function digU() --Dig up (above the turtle) function
turtle.digUp()
sleep(0.50)
end
function digD() --Dig down (below the turtle) function
turtle.digDown()
sleep(0.50)
end
while true do --Code to wait for a command, if a certain message is recieved, a certain function is given.
id, msg = rednet.receive()
if msg == "f" then
forward()
end
if msg == "b" then
back()
end
if msg == "r" then
right()
end
if msg == "l" then
left()
end
if msg == "u" then
up()
end
if msg == "d" then
down()
end
end
Thanks!