Computer/Turtle Craft Scripts (Share & Request)

  • Please make sure you are posting in the correct place. Server ads go here and modpack bugs go here
  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

SReject

New Member
Jul 29, 2019
433
0
0
Since I don't see one of these I figured I'd start one (and hopefully the mods will sticky the thread). But in any case, lets have those delicious scripts, and if you need some help, ask away.
 

SReject

New Member
Jul 29, 2019
433
0
0
It would actually be a much better idea to go to the ComputerCraft forums if you want computer help, specifically their Ask a Pro subforum. There is also a Programs subforum, as well, for sharing programs.
I understand this, and with just computercraft I'd probably suggest individuals to check their forums, but with all the mods that ftb offers WITH computer craft, I feel it better to have a script thread here. I mean, what if someone wanted to move soul shards around. Since its not a 'super common' mod, those that might be able to help might look at it and appear clueless :)
 

Guswut

New Member
Jul 29, 2019
2,152
0
0
I understand this, and with just computercraft I'd probably suggest individuals to check their forums, but with all the mods that ftb offers WITH computer craft, I feel it better to have a script thread here. I mean, what if someone wanted to move soul shards around. Since its not a 'super common' mod, those that might be able to help might look at it and appear clueless :)

Understandable. I just don't think we'll see any traction here, but then nature shall take its course.

As a start, here is a very basic timer script which switched between two states given a certain number of cycles, as well as displays what the current state is and how much longer until the next state (also, any key to end support [sans ESC key]). I'm sure there is room for improvement, but I don't want to have to ever touch my sugarcane farm again:

http://pastebin.com/HActwMMm
Code:
bEnd = false
 
parallel.waitForAny(
function()
  while true do
  redstone.setOutput("bottom",true)
  redstone.setOutput("top",false)
 
  iCounterNeg=60
 
  for iCounter=1,600,1 do
    shell.run('clear')
    print("Harvesting...")
    iCounterNeg=iCounterNeg-0.1
    print("Time remaining until WAITING: "..iCounterNeg.." seconds")
    print("")
    print("Press any key (except ESC) to end")
    sleep(0.1)
  end
 
  redstone.setOutput("bottom",false)
  redstone.setOutput("top",true)
 
  iCounterNeg=180
 
  for iCounter=1,1800,1 do
    shell.run('clear')
    print("WAITING")
    iCounterNeg=iCounterNeg-0.1
    print("Time remaining until HARVEST: "..iCounterNeg.." seconds")
    print("")
    print("Press any key (except ESC) to end")
    sleep(0.1)
  end
  end
end,
 
function()
  while not bEnd do
  local event, key = os.pullEvent("key")
  if key ~= keys.escape then
    bEnd = true
  end
  end
end
)
 
shell.run('clear')
 
redstone.setOutput("bottom",false)
redstone.setOutput("top",true)
 
print("Farm Turned Off")
 

KirinDave

New Member
Jul 29, 2019
3,086
0
0
The computercraft forums are indeed the best place to go. Don't go to that one site I won't name that is trying to set up a "community" around computercraft with "premium" scripts. The quality of the code (and the people who wrote it) will make your eyes melt.
 

Guswut

New Member
Jul 29, 2019
2,152
0
0
The computercraft forums are indeed the best place to go. Don't go to that one site I won't name that is trying to set up a "community" around computercraft with "premium" scripts. The quality of the code (and the people who wrote it) will make your eyes melt.

Saying something like that is just going to make people want to see whatever it is that you are hinting at, as I'm sure the vast majority of people (myself included) have no idea what you are talking about.
 

Guswut

New Member
Jul 29, 2019
2,152
0
0
@Guswut, stealing the esc to quit right NOA! :p

Go for it. I wish I could have stolen it from my future self as I kept losing programs before I looked up the proper force-termination command. Coming from Windows, I was expecting "CTRL-C" to abort the current script, so it resulted in a few lost computers. Thankfully, this was before I knew you could label your computers to retain data on them, otherwise I would have been out some computers entirely.
 

SReject

New Member
Jul 29, 2019
433
0
0
Here's a question. If I have a few turtles and I want them all to execute the same program, is there a way for me to have that program stored in a central location, and on startup of the turtles they grab it and execute it?

I have 19 melee turtles all in a line, and as I adjust their startup code, I'd be nice to update it in a single place and all the turtles update
 

KirinDave

New Member
Jul 29, 2019
3,086
0
0
Do also remember that holding Control-T will terminate any program that is not specifically blocking that feature.

By the way, if you like that you might like code with this shape. And also if you want to make really smart-looking programs, use coroutines. They let you write functions that are a lot like suspend-able, resumable, restartable threads.[DOUBLEPOST=1360955614][/DOUBLEPOST]
Here's a question. If I have a few turtles and I want them all to execute the same program, is there a way for me to have that program stored in a central location, and on startup of the turtles they grab it and execute it?

I have 19 melee turtles all in a line, and as I adjust their startup code, I'd be nice to update it in a single place and all the turtles update

One fun way to do this would be to have one master computer with rednet and each wireless turtle could send out a message to their master on /startup "I am a melee turtle with name X, please give me a program to run." Your master task dispatcher could then give them the code. You could even have a variety of work orders which the master could select, and store your programs on disks, and have the master display the last known status of the various turtles that have asked for job code.
 

SReject

New Member
Jul 29, 2019
433
0
0
C and javascript guy here. So Lua, thus far, has been pretty easy to pick up. It's just figuring out routines and the such opened up by computercraft[DOUBLEPOST=1360955748][/DOUBLEPOST]
One fun way to do this would be to have one master computer with rednet and each wireless turtle could send out a message to their master on /startup "I am a melee turtle with name X, please give me a program to run." Your master task dispatcher could then give them the code. You could even have a variety of work orders which the master could select, and store your programs on disks, and have the master display the last known status of the various turtles that have asked for job code.
I looked into this earlier but couldn't figure out exactly how to get the code from the control computer to the turtles, then run it
 

Guswut

New Member
Jul 29, 2019
2,152
0
0
C and javascript guy here. So Lua, thus far, has been pretty easy to pick up. It's just figuring out routines and the such opened up by computercraft[DOUBLEPOST=1360955748][/DOUBLEPOST]
I looked into this earlier but couldn't figure out exactly how to get the code from the control computer to the turtles, then run it

I really dislike the syntax, as it feels far too wordy, but yes, it is extremely easy to pick up.

You are best off enabling the HTTP functionality so you can use the PASTEBIN command to obtain the script from pastebin.com, as opposed to resending the script via rednet every time you need to make a change. You'd then just need to rednet your computers together to accept a reload-script command, or just run red wire and have them check a side for that.

An example of the command you would use to use the PASTEBIN command in LUA: shell.run("pastebin","get <CODE> <newFileName>")
 

KirinDave

New Member
Jul 29, 2019
3,086
0
0
C and javascript guy here. So Lua, thus far, has been pretty easy to pick up. It's just figuring out routines and the such opened up by computercraft[DOUBLEPOST=1360955748][/DOUBLEPOST]
I looked into this earlier but couldn't figure out exactly how to get the code from the control computer to the turtles, then run it

Probably the most trivial: You can write to a file then call shell.run.
 

SReject

New Member
Jul 29, 2019
433
0
0
Actually, my only question is how to get wireless turtles onto the network? I can get the computer up and using rednet no problem, but actually accessing the wireless turtle's modem has me confused
 

Guswut

New Member
Jul 29, 2019
2,152
0
0
Actually, my only question is how to get wireless turtles onto the network?

Add a modem (http://computercraft.info/wiki/Modem) to your computer/turtle, then open a program and use the rednet.open(<SIDE>) command to start rednet for that modem. You will then have to start broadcasting and receiving utilizing the rednet API calls, but that isn't too bad. If you use pastebin, you shouldn't have to do more than broadcast when an update needs to be run.
 

SReject

New Member
Jul 29, 2019
433
0
0
Actually wasn't too difficult:

Code:
--Control computer Startup:
f = fs.open("TurtleOrders", "r")
startUpCode = f.readAll()
f.close
 
rednet.open("right")
while true do
    local sender, msg, a = rednet.receive()
    if sender and msg == "need orders" then
        rednet.send(sender, "command:" .. startUpCode)
    end
end
 
 
--Turtle's Startup:
rednet.open("right")
while true do
    rednet.broadcast("need orders")
    local sender, msg, a = rednet.receive(60)
    if sender and string.sub(msg,1,8) == "command:" then
        assert(loadstring(string.sub(msg,9)))()
        break
    end
end
 

jumpfight5

New Member
Jul 29, 2019
1,750
0
1
Well, there is a similar thread (very similar, infact) with lots of good codes already. A member NosePicker5555 made it and it has a decent amount of codes. It's up to you if you want to go revert everything onto his thread or make your own, but I think it'd be easier if you just used his.
 

Guswut

New Member
Jul 29, 2019
2,152
0
0
Well, there is a similar thread (very similar, infact) with lots of good codes already. A member NosePicker5555 made it and it has a decent amount of codes. It's up to you if you want to go revert everything onto his thread or make your own, but I think it'd be easier if you just used his.

Can you provide a link to this thread?