Jump to content




New to CC and singing the frame quarry blues

computer lua wireless

  • You cannot reply to this topic
5 replies to this topic

#1 arempi

  • New Members
  • 2 posts

Posted 05 December 2013 - 08:13 PM

Hello Everyone,

This is my first post on the forum and first time playing with cc. I dont have much, if any programming or scripting experience so this might be a simple question - or a funny monkey rigged concept. I'm trying to make a Redstone in motion mining well quarry with control via CC. I'm using the "carriage engine" as the pilot for platform and utilizing rs.setOutput give it a redstone pulse. One of the first real issues I've noticed was that Computers and Turtles reboot when moved. To over come this I came up with the idea of having a control computer on the ground somewhere -rednet.send to 4 wireless turtles sorrounding the carriage engine. I dont really know the range of the rednet signals?

I started looking for existing programs out there and found this:

Spoiler


http://pastebin.com/nTFx8ajQ

However its using rs.setBundledOutput and I did not know how to edit the program itself to send a msg to specified turtle to tell it to emit redstone puls. So I being the monkey rigger tried to have one computer run the quarry program and send the signals though MFR rednet cable to another computer that was open to wireless and had directions to send msg to right computer depending on color of bundled cable signal it received. The program I pieced together for this broadcaster:

rednet.open("right")
while true do
  if (colors.test (rs.getBundledInput("left"), colors.blue)) then
  rednet.send(4, "pulse")
  end
  if (colors.test (rs.getBundledInput("left"), colors.orange)) then
  rednet.send(5, "pulse")
  end
  if (colors.test (rs.getBundledInput("left"), colors.purple)) then
  rednet.send(6, "pulse")
  end
  if (colors.test (rs.getBundledInput("left"), colors.yellow)) then
  rednet.send(2, "pulse")
  end
end
http://pastebin.com/j7a54102
(however I'm having issues keeping this program looping indefinetely so it can always broadcast when it recieves a redstone pulse)

The turtles have this program running:
rednet.open("right")
while true do
  id,message = rednet.receive()
	if id == 3 then
	  if message == "pulse" then
		rs.setOutput("front", true)
		end
	  end
	end
http://pastebin.com/UDjmKyRZ
and
Using this for thier Startup program:
sleep(1)
shell.run("wireless")
http://pastebin.com/KJU5mBtV

I think the main problem right now is getting the broadcast computer to keep looping without getting the "Too long without yeilding"
Might be having an issue with the startup program on the frame computers.

Like I said before, I'm rather new to all this. Not sure what to make of it all but after messing around for some time I got a bit frustrated ;p
I saw another program on this forum that would save the blocks to move/direction in a file and would modify it every reboot. But I did not get that to work: Link Kept getting some 'nil' error.

Is this a viable way to do this? If so, how can I get this all to mesh together and work? Any input would be apprecieted. If you have a working program other than this I'd love to try to give it a go.

Thanks,
Arempi

#2 awsmazinggenius

  • Members
  • 930 posts
  • LocationCanada

Posted 05 December 2013 - 08:56 PM

Hello,

You are missing and 'end' statement on your while statement. Also, indent with 2 or 4 spaces (tabs don't always like to play nicely), but please keep it consistent. Use sleep() calls every once in a while (and actually delay a second or two if possible - it reduces server load) to yield. os.pullEvent(), as well as other functions, yield your program as well. I'm not completely getting your issue, feel absolutely to post again with further details or to shoot me a PM. Have you tried a syntax checker? Some are actually half-decent at doing their job.

#3 arempi

  • New Members
  • 2 posts

Posted 07 December 2013 - 06:05 AM

Thanks for the reply. Not sure which 'while' statement you were refering too. The program the turtles are using seems right, when I add another end it errors. I think I might just use a timer and go low tech.

#4 awsmazinggenius

  • Members
  • 930 posts
  • LocationCanada

Posted 08 December 2013 - 12:59 PM

Sorry, that would be my mistake. I am referring to the turtle program (3rd example including spoiler), which is indented inaccurately so I thought an end statement was missing. (Sometimes the forum derps up your posts). "Too long without yielding" is when your program runs for 10 seconds without a yield (sleep(), os.pullEvent(), read()) and is CC's protection to make sure your computer - and the server - doesn't blow up.

#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 08 December 2013 - 04:16 PM

os.pullEvent() yields until certain events happen. Usually you'd store information about those events in some variables, but in this case, all you're interested in is that the event has happened (in this case, a change in the redstone input):

rednet.open("right")
while true do
  os.pullEvent("redstone")
  if (colors.test (rs.getBundledInput("left"), colors.blue)) then
  rednet.send(4, "pulse")
.
.
.

Or maybe add that line at the bottom of the loop, depending on whether you want it to hold off on the if/then checks until the first redstone state change.

If you want it to keep sending pulses "all the time", not just when the redstone input changes, then use sleep() (which also yields). It doesn't need to sleep for long - but since ComputerCraft can only execute one script at a time (per MineCraft server!), yielding is necessary so that other scripts get a chance to do their thing. Hence why it shuts them down if they don't do it.

Edited by Bomb Bloke, 08 December 2013 - 04:21 PM.


#6 awsmazinggenius

  • Members
  • 930 posts
  • LocationCanada

Posted 08 December 2013 - 07:25 PM

For pulses "all the time", could one not simply use a redstone clock circut? It could be activated by a computer if necessary.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users