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

2 part question: changing id's and end program on key press?

Started by gronkdamage, 20 March 2013 - 12:15 AM
gronkdamage #1
Posted 20 March 2013 - 01:15 AM
Question #1: I have 6 mining turtles: Is there a way of making all 6 turtles have the same id (so if I change a program on the first one, the other 5 are all going to have access to that program?)

Part 2 of that question: what happens if multiple turtles are forced to have the same id? (ie. you plop down a turtle, label it - go to the server and delete the lastid.txt - and then plop down a 2nd turtle and give it the exact label. (I did this on accident, but wasn't sure if it would break something…))



Question #2: Is there a way (in code or whatever) to run an application and basically say repeat until the space bar is pressed? I know you can end a program via ctrl T - but there have been times when I start a program (say a floor builder) and realize I screwed up - the turtle won't react to ctrl t (ie. i'm not fast enough (it's moved away) - or it just ignores it for a few seconds…)


Thanks!
Viproz #2
Posted 20 March 2013 - 01:18 AM
for the second, you must use os.pullEvent(), see the wiki here : http://computercraft.info/wiki/Os.pullEvent

For the fist question, i have no idea
Theray070696 #3
Posted 20 March 2013 - 01:30 AM
To answer the first question, you can in creative mode. Just break the turtle then middle click on it in your inventory to get a stack. They will now share id's, but not fuel levels. Middle clicking on the turtle in the world will also give you a copy with the same Id and label. You also could spawn it in with NEI. I've done this before with a house builder and there are no negative effects (besides having to refuel all of them).
LazyBoot #4
Posted 20 March 2013 - 02:05 AM
This will stop if you press any other button then esc


local bEnd = false;
parallel.waitForAny(
function()
  while not bEnd do
   local event, key = os.pullEvent("key");
   if key ~= 1 then
	bEnd = true;
	print("Aborting...");
   end
  end
end,
function()
  while not bEnd do
   -- Put normal code here
  end
end
)
theoriginalbit #5
Posted 20 March 2013 - 02:14 AM
This will stop if you press any other button then esc


local bEnd = false;
parallel.waitForAny(
function()
  while not bEnd do
   local event, key = os.pullEvent("key");
   if key ~= 1 then
	bEnd = true;
	print("Aborting...");
   end
  end
end,
function()
  while not bEnd do
   -- Put normal code here
  end
end
)
The escape key is NEVER passed to the terminal, there will never be an event with key code 1. so really you can just do this for the code

os.pullEvent("key")
and that will pause there until any key is pressed.

however the OP didn't want this, they wanted on spacebar pressed exit the program. so to OP you can do this

local e, p = os.pullEvent()
if e == 'key' and p == key.space then
  error() -- there are a few other ways to do it, but error will exit the program no matter where it is in the code. if its the program block then you could use return.
end
robhol #6
Posted 20 March 2013 - 02:48 AM
For the program sharing, you'll need access to the CC files (they're in your MC save directory) and be able to create a symlink (google it and include your OS), that's how I'm doing it. Delete your "drone" turtle folders (id) and create links to the one you'll be updating where they were. Make sure they're working using ls or something like that.
gronkdamage #7
Posted 20 March 2013 - 10:47 AM
Thanks everyone! :)/> I'll check out all the info.
sithrazer #8
Posted 20 March 2013 - 06:34 PM
The escape key is NEVER passed to the terminal, there will never be an event with key code 1. so really you can just do this for the code

I'm only replying because I ran into this just the other day. It appears the escape key is being passed to the terminal…at least, when the terminal is a turtle. I haven't tested with a non-turtle to see if it makes a difference.
http://pastebin.com/NKFrJtJu <- Code for the program
http://en.zimagez.com/zimage/2013-03-20012610.php <- screenshot of result when pressing 'esc' to exit the turtle's interface while the program is running.

I added the extra print line to show the key code of the button pressed for clarity.
gronkdamage #9
Posted 20 March 2013 - 06:46 PM
I have yet another question on this subject :)/> Is it possible to have a turtle (well, the computer) execute an external program? My thought on updating all turtles was to write an external .exe (or batch file) - so players can update the programs themselves… A friend brought up a good point on the sync thing: "what if you don't like the program - why have it update?"
Shnupbups #10
Posted 20 March 2013 - 07:15 PM
If you are in creative and want to do Question 1, you can label a turtle, break it, and then place it however many times you like.
LordIkol #11
Posted 20 March 2013 - 09:40 PM
I have yet another question on this subject :)/> Is it possible to have a turtle (well, the computer) execute an external program? My thought on updating all turtles was to write an external .exe (or batch file) - so players can update the programs themselves… A friend brought up a good point on the sync thing: "what if you don't like the program - why have it update?"

As dar as i know its not possible to Run Programs from a turtle or to access any other Folder than the turtles Homefolder and its subfolders.
But there is a MOD that adds Batch Turtles which can Execute Batch Files. Check Out Here
So you could add the Update to a folder and then run the batch file that puts it to all the other turtles folders

Greets
Loki
PixelToast #12
Posted 21 March 2013 - 02:43 AM
I have yet another question on this subject :)/> Is it possible to have a turtle (well, the computer) execute an external program? My thought on updating all turtles was to write an external .exe (or batch file) - so players can update the programs themselves… A friend brought up a good point on the sync thing: "what if you don't like the program - why have it update?"
yes, just send the files over rednet, or use http, its been done so many times