This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Gotrek65's profile picture

Rednet Arrays and turtles

Started by Gotrek65, 23 March 2013 - 07:56 PM
Gotrek65 #1
Posted 23 March 2013 - 08:56 PM
Ok so what I have going is a line of 17 turtles running the same program on the command of a computer. I want the turtles to send a rednet message to the computer modifying an array key to true each turtle having it's own key. I'm unsure how to send a rednet message to the computer to modify it's specific array key.


So then on the master computer I was trying to get the following to work



a = {}  --creates array

for i = 1, 17 do --creates 17 entries into array
  a[i] = "false"  --sets all 17 entries to false
end

if recieving redstone signal from wireless transmitter(i dont know how to code that) then
  for i = 1, 17 do
	if a[i] = "true" then
	  shell.run("move")
	  sleep(5)
	  shell.run("dig")
	else
	  sleep(5)
	end
  end
end
Once all keys in the array are true then the computer moves everything sleeps and runs the dig program on all the computers which is the following

rednet.open("right")
for i = 4, 20 --IDs of the turtles
  rednet.send(i, "cycle")
end

I tried doing the program in lua before actually building the program. I was able to set all 17 entries of the array to false but when trying to get the following command to work

for i = 1, 17 do if a = "false" then print("success") end

but it keeps giving me

lua:36: [string "lua"]:1: 'then' expected
jadelade #2
Posted 23 March 2013 - 09:43 PM
do you want all the turtle to do the same thing
ok i get it now lol derp
Gotrek65 #3
Posted 24 March 2013 - 03:52 AM
so anyone that can help me with my predicament?
jadelade #4
Posted 24 March 2013 - 04:07 AM
well i'm having trouble understanding what you want. this what i think you want.
the main computer sends out a signal saying go and changes all the values in the table to true
the turtle receives the signal and runs a program.
i think i got it right.

1) you use rednet.receive(varOne) to receive a signal
in the place of varOne you would put a number this is the time it will wait for a signal but if you leave that out it will wait until it gets a signal

2) true and false variables can be set like this

varOne = true
varTwo = false
unless you want text to replace them
Gotrek65 #5
Posted 24 March 2013 - 04:21 AM
So I did a bit more coding this morning figured out that my if then statement issues(edit sorry about the mess)

if a[i] = true then
changed it to the following and it works

if (a[i]) == ("true") then
I still need help with the turtles sending a command to the computer to modify their array key
Gotrek65 #6
Posted 24 March 2013 - 04:24 AM
well i'm having trouble understanding what you want. this what i think you want.
the main computer sends out a signal saying go and changes all the values in the table to true
the turtle receives the signal and runs a program.
i think i got it right.

1) you use rednet.receive(varOne) to receive a signal
in the place of varOne you would put a number this is the time it will wait for a signal but if you leave that out it will wait until it gets a signal

2) true and false variables can be set like this

varOne = true
varTwo = false
unless you want text to replace them
the main computer resets all array values to false before telling the turtles to "cycle" when the turtles finish they tell the computer for example the first turtle on the left will tell the computer a[1] == "true" once all values are true signaling all turtles are finished frame move forward and start the process again.