Jump to content




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


6 replies to this topic

#1 S16IceMan

  • New Members
  • 9 posts

Posted 03 August 2012 - 05: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()
Attached Image: Script 1.jpg
Attached Image: Script 2.jpg

[EDIT 3]
Here is the broadcast program

Attached Thumbnails

  • Attached Image: Script 3.jpg


#2 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 03 August 2012 - 05: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 by craniumkid22, 03 August 2012 - 05:31 PM.


#3 BigSHinyToys

  • Members
  • 1,001 posts

Posted 03 August 2012 - 05:31 PM

Use the tonumber() function simple ha this may help you
http://www.lua.org/manual/5.1/

#4 S16IceMan

  • New Members
  • 9 posts

Posted 03 August 2012 - 05: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.

#5 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 03 August 2012 - 06:05 PM

View PostS16IceMan, on 03 August 2012 - 05:57 PM, said:

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

View PostS16IceMan, on 03 August 2012 - 05:57 PM, said:

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!


#6 S16IceMan

  • New Members
  • 9 posts

Posted 03 August 2012 - 06:10 PM

They can output redstone charges?...

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


i fail at life.

#7 S16IceMan

  • New Members
  • 9 posts

Posted 03 August 2012 - 06:25 PM

just ran the new code you guys suggested. It works perfectly Thank you so much!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users