Posted 16 May 2016 - 02:14 AM
I have a created a program that allows the user to control a wireless robot using aswd (left, back, forwards, and right) g for up and d for down when holding a pocket computer - eventually it will also place and break blocks. That worked fine, the robot moved based on the message received, but then I thought I would make a segment of code that would make the robot run in a pattern such as creating a platform 10x10. I tried making this code but I got stuck and I dont know how. Currently the robot code runs fine (no errors) but the pocket computer shows the name of the that was run last, its meant to clear and then print Height, Direction, Forwards and Back. Any ideas on how to fix it?
The code in blue segment (near the bottem) I think should toggle between allowsqaure yes and no, the turtle did receive the signal and printed "start making square" but doesn't seem to toggle between, any ideas? (but since changing/adding it hasnt received or send anything)
this is my code currently (pocket computer) code, everything new is labled (if the new code was removed it would just move and print proper text (Height, Direction, Forwards and Back)
And the robots code, again everything new is labled ect.
The code in blue segment (near the bottem) I think should toggle between allowsqaure yes and no, the turtle did receive the signal and printed "start making square" but doesn't seem to toggle between, any ideas? (but since changing/adding it hasnt received or send anything)
this is my code currently (pocket computer) code, everything new is labled (if the new code was removed it would just move and print proper text (Height, Direction, Forwards and Back)
rednet.open("back")
local disf = 0
local dire = 0
local disv = 0
while true do
local sender, message, protcol = rednet.receive() --- new
if message == "squareon" then ----- new from here
allowsquareYN = 1
end
if message == "squareoff" then
allowsquareYN = 0
end ----- to here
term.clear()
term.setCursorPos(1,1)
print("Height "..disv)
print("Direction "..dire)
print("Forwards "..disf)
print("Back "..disf)
print("Allow Square = "..allowsquareYN) ---- new
local event, character = os.pullEvent("char")
if character == "w" then
rednet.broadcast("forward")
end
if character == "a" then
rednet.broadcast("left")
end
if character == "s" then
rednet.broadcast("back")
end
if character == "d" then
rednet.broadcast("right")
end
if character == "g" then
rednet.broadcast("godown")
end
if character == "h" then
rednet.broadcast("goup")
end
if character == "u" then
rednet.broadcast("allowsquaremsg")
end
if character == "j" then
rednet.broadcast("tenxten")
end
end
And the robots code, again everything new is labled ect.
rednet.open("left")
while true do
local sender, message, protcol = rednet.receive()
if message == "left" then
turtle.turnLeft()
print("moving left")
end
if message == "right" then
turtle.turnRight()
print("moving right")
end
if message == "back" then
turtle.back()
print("going backwards")
end
if message == "forward" then
turtle.forward()
print("moving forwards")
end
if message == "goup" then
turtle.up()
print("moving up")
end
if message == "godown" then
turtle.down()
print("moving down")
end
if message == "allowsquaremsg" then ---- blue segment
print("starting make square")
if allowsqare == 1 then
allowsquare = 0
print("false therefore 0")
rednet.broadcast("squareoff") -- this line is also new
[color=#000080] end
if allowsquare == 0 then
allowsquare = 1
print("true or 1")
rednet.broadcast("squareon") -- this line is also new
[color=#000080] end
end
---- end of blue segment
---------------Preset Movements--------
while allowsquare == 1 do
local tenxtenf = 0
local tenxtens = 0
local tenxtennum = 0
local tenxtendir = 1
if message == "tenxten" then
print("moving in a 10x10")
while tenxten == 0 do
turtle.forward(9)
tenxtenf = 1
end
else
turtle.turnRight()
turtle.forward()
turtle.turnRight()
tenxtenf = 0
tenxtennum = 1
end
end
end
I tried changing the font colour but because its code it didnt like it