Posted 05 September 2012 - 04:59 AM
Hey, guys. I am very new to Lua and coding in general, but I believe I am slowly grasping the concept. My question deserves a bit of a run down on the program I am trying to make. It is a simple Mineshaft digging program that sends stats such as: how far the turtle has gone, how far he has left, how many torches does he have left, and so on. I then wrote a program for the computer in my main base to redirect all that info onto a monitor (4x3). I created a loop that says
for i=0,11
do
local event,p1,p2 = os.pullEvent()
if event == "rednet_message" then
print(p2)
end
end
term.clear()
Repeat()
end
The loop repeats 11 times because there are 11 things that the turtle sends each time he sends data, this includes a line of "*" on the top and bottom.
Well….this does'nt work! The only way I was able to make it work was to actually have the turtle send 12 things instead of 11 (it adds an extra line of no text). That would work for a while and then the monitor would return a "java.lang.arrayIndexOutofBoundsException" error, then works again after rebooting the receiving Terminal.
My main goal is to have the monitor receive 11 lines through rednet, input them on the screen then right before it receives the next set of 11 lines it clears the previous and then writes the new set… I really hope that makes sense, if not let me know and I will try to explain a bit better!
Any help would be greatly appreciated!
edit: Just to give a bit more information. This is what the turtle is sending to the home Computer:
rednet.send(0, " Currently Mining")
rednet.send(0, "*************************************")
rednet.send(0, "Blocks from Starting Position: " ..z)
rednet.send(0, "Total Blocks Moved: " ..x)
rednet.send(0, "Layers Left: " ..i)
rednet.send(0, "Current Fuel Level: " ..turtle.getFuelLevel())
rednet.send(0, turtle.getItemCount(1).. " CobbleStone Left")
rednet.send(0, turtle.getItemCount(2).. " Torches Left")
rednet.send(0, "Coal Left in Inventory: " ..turtle.getItemCount(16))
rednet.send(0, "Blocks Moved Until Torch: "..5-q)
rednet.send(0, "*************************************")
Edit 2: I suppos what I'm ultimatley after is the ability to send all 11 messages in the form of one message, but still include all the variables. Kind of like the "print[[" command or others like it. That way I can just use the "term.clear()" at the beginning of each loop. But I'm not sure if this is possible.
Edit 3: Upon further debugging I have found that the recursion loop that I used in a big "No No" and that is why I received the Java error. But I only started using that loop because the tried and true "for i=0,11" loop did not function correctly. Also it seems that the reason I needed the blank message at the begining of the other Rednet messages is because the terminal was having trouble receiving the first message everytime it rebooted. Is there a way around this?
Spoiler
function Repeat()for i=0,11
do
local event,p1,p2 = os.pullEvent()
if event == "rednet_message" then
print(p2)
end
end
term.clear()
Repeat()
end
The loop repeats 11 times because there are 11 things that the turtle sends each time he sends data, this includes a line of "*" on the top and bottom.
Well….this does'nt work! The only way I was able to make it work was to actually have the turtle send 12 things instead of 11 (it adds an extra line of no text). That would work for a while and then the monitor would return a "java.lang.arrayIndexOutofBoundsException" error, then works again after rebooting the receiving Terminal.
My main goal is to have the monitor receive 11 lines through rednet, input them on the screen then right before it receives the next set of 11 lines it clears the previous and then writes the new set… I really hope that makes sense, if not let me know and I will try to explain a bit better!
Any help would be greatly appreciated!
edit: Just to give a bit more information. This is what the turtle is sending to the home Computer:
Spoiler
rednet.send(0, "") —–Notice the extra line of no Informationrednet.send(0, " Currently Mining")
rednet.send(0, "*************************************")
rednet.send(0, "Blocks from Starting Position: " ..z)
rednet.send(0, "Total Blocks Moved: " ..x)
rednet.send(0, "Layers Left: " ..i)
rednet.send(0, "Current Fuel Level: " ..turtle.getFuelLevel())
rednet.send(0, turtle.getItemCount(1).. " CobbleStone Left")
rednet.send(0, turtle.getItemCount(2).. " Torches Left")
rednet.send(0, "Coal Left in Inventory: " ..turtle.getItemCount(16))
rednet.send(0, "Blocks Moved Until Torch: "..5-q)
rednet.send(0, "*************************************")
Edit 2: I suppos what I'm ultimatley after is the ability to send all 11 messages in the form of one message, but still include all the variables. Kind of like the "print[[" command or others like it. That way I can just use the "term.clear()" at the beginning of each loop. But I'm not sure if this is possible.
Edit 3: Upon further debugging I have found that the recursion loop that I used in a big "No No" and that is why I received the Java error. But I only started using that loop because the tried and true "for i=0,11" loop did not function correctly. Also it seems that the reason I needed the blank message at the begining of the other Rednet messages is because the terminal was having trouble receiving the first message everytime it rebooted. Is there a way around this?
Edited on 05 September 2012 - 05:47 AM