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

need help programming turtle... I'm about to take a nuke to the whole thing...

Started by S16IceMan, 03 August 2012 - 04:17 PM
S16IceMan #1
Posted 03 August 2012 - 06:17 PM
So here's my genius plan…
i want 20 wireless turtles to move a certain distance at the same time from receiving a distance via a computer's red net.broadcast(). I'm making the broadcast a single number (let's use 10 for this example). The turtles are supposed to read the number broadcasted via an event, id, text =os.pullEvent script that only designates the text.

the problem is…

i have no clue how to convert the 10 from string to a number the turtles can read and act upon… I'm trying to use i=1,Num with local num=text, but i don't know how to format it.

[EDIT] It either returns as a num expected string given error or something similar to that.

Simple solution I'm missing, or is this a lot more complicated than i was hoping?

:P/>/>

[EDIT 2]
Here are the screenshots after I tried to use tonumber()
[attachment=363:Script 1.jpg]
[attachment=364:Script 2.jpg]

[EDIT 3]
Here is the broadcast program
Cranium #2
Posted 03 August 2012 - 06:29 PM
You should eb able to do this as long as the turtles are in range.
sender:

rednet.open("side")
rednet.broadcast("10")
receiver:

while true do
id, msg, dist = rednet.receive(1)
  if msg == "10" then
	--your placement code here
  else
	os.reboot()
  end
end
The turtles should be able to receive 10 as a string, since you are designating it as a string already. Not sure if that's what you want. Post otherwise…

P.S. It would help to know what you want to do if you post a little of your code, so we can know in what context you want them to move…
Edited on 03 August 2012 - 04:31 PM
BigSHinyToys #3
Posted 03 August 2012 - 06:31 PM
Use the tonumber() function simple ha this may help you
http://www.lua.org/manual/5.1/
S16IceMan #4
Posted 03 August 2012 - 06:57 PM
Thanks for the quick responses. I tried to use tonum() and it gave me a nil. I'll try to put in the right request this time, haha. I'll give it a shot and see if it works.

As for the code…

I'm trying to have the turtles do a bombing run over a certain distance, but because I'm running tekkit and the latest only has 1.3, I can't use place and attack, so i have to be more creative. I made the turtles place a tnt block in front, go up, place a sand block, go up, place a stone plate, then drive over it. Well… i was TRYING to make them do it.

I'll add a screenshot to the main post.
MysticT #5
Posted 03 August 2012 - 07:05 PM
Thanks for the quick responses. I tried to use tonum() and it gave me a nil. I'll try to put in the right request this time, haha. I'll give it a shot and see if it works.
It's tonumber, not tonum:

local evt, id, msg = os.pullEvent("rednet_message") -- or: local id, msg = rednet.receive()
local num = tonumber(msg)
if num then -- check if it's a number
  -- do something
end

As for the code…

I'm trying to have the turtles do a bombing run over a certain distance, but because I'm running tekkit and the latest only has 1.3, I can't use place and attack, so i have to be more creative. I made the turtles place a tnt block in front, go up, place a sand block, go up, place a stone plate, then drive over it. Well… i was TRYING to make them do it.
Why bother with that much work, when you can simply place the tnt and set redstone output on the turtle:

turtle.place() -- place the tnt
rs.setOutput("front", true) -- turn on the tnt!
-- tnt falls
-- boom!
S16IceMan #6
Posted 03 August 2012 - 07:10 PM
They can output redstone charges?…

http://i0.kym-cdn.co...54/facepalm.jpg


i fail at life.
S16IceMan #7
Posted 03 August 2012 - 07:25 PM
just ran the new code you guys suggested. It works perfectly Thank you so much!