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

Topic hijac question about APIs.

Started by Ninjawolf0007, 02 December 2013 - 10:06 AM
Ninjawolf0007 #1
Posted 02 December 2013 - 11:06 AM
Is there a way to add api's to a server? Would it have to be a resource pack and if so, would I need to constantly unzip it to modify the code in it or can it be a regular folder, not a .zip? I'm using ComputerCraft1.57 for minecraft 1.6.4 with the newest forge version. I haven't tried a resource pack but every time I try to unzip computercraft and get around the lua/rom mounting error, I've been unsuccessful.
Edited on 02 December 2013 - 10:10 AM
Zudo #2
Posted 02 December 2013 - 12:25 PM
Is there a way to add api's to a server? Would it have to be a resource pack and if so, would I need to constantly unzip it to modify the code in it or can it be a regular folder, not a .zip? I'm using ComputerCraft1.57 for minecraft 1.6.4 with the newest forge version. I haven't tried a resource pack but every time I try to unzip computercraft and get around the lua/rom mounting error, I've been unsuccessful.

Please don't hijack topics.

If you want to add an api to a specific computer, you can open <server folder>/<world folder>/computer/<id> and put it there.
Ninjawolf0007 #3
Posted 02 December 2013 - 01:00 PM
Sorry, but I want the api to be accessed from more than one turtle without having to place it in each turtle individually.
Ninjawolf0007 #4
Posted 02 December 2013 - 01:12 PM
How do you get multiple turtles to load an api that you made in game if it's not in the api folder?

I made an api on one turtle and I want to load it on another, how would I do that? I am using ComputerCraft 1.57 for minecraft 1.6.4.
Edited on 02 December 2013 - 12:54 PM
TheOddByte #5
Posted 02 December 2013 - 02:29 PM
How do you get multiple turtles to load an api that you made in game if it's not in the api folder?

I made an api on one turtle and I want to load it on another, how would I do that? I am using ComputerCraft 1.57 for minecraft 1.6.4.
Wow.. Nice necromancing skills :P/>
Anyway.. Are you trying to load an API from a turtle that is on another turtle? O_o
Well you need to have it on the other turtles. Maybe by letting them stand next to a disk drive and let them copy it from there, Or simply send the file through rednet, Or even better.. Pastebin :P/>
Ninjawolf0007 #6
Posted 02 December 2013 - 02:36 PM
Spoiler
How do you get multiple turtles to load an api that you made in game if it's not in the api folder?

I made an api on one turtle and I want to load it on another, how would I do that? I am using ComputerCraft 1.57 for minecraft 1.6.4.

Wow.. Nice necromancing skills :P/>
Anyway.. Are you trying to load an API from a turtle that is on another turtle? O_o
Well you need to have it on the other turtles. Maybe by letting them stand next to a disk drive and let them copy it from there, Or simply send the file through rednet, Or even better.. Pastebin :P/>

Thanks :P/>
From one turtle to another, yes. Is there a way to "broadcast" an api over rednet? or better yet, broadcast the pastebin function to all turtles/computers?
TheOddByte #7
Posted 02 December 2013 - 03:34 PM
Okay, Todo this you must have the turtles receiveing ofcourse.
Now here's a way todo it.

Transmitter

term.clear()
term.setCursorPos(1,1)
write("File: ")
local filename = read()

local code
if fs.exists(filename) then
    local f = fs.open(filename, "r")
    code = f.readAll()
    f.close()
    print("Broadcasting code!")
    rednet.broadcast(code)
else
    print("File didn't exist!")
end

Receiver

local id, code = rednet.receive()
local file = fs.open("YourFile", "w")
file.write(code)
file.close()
Ninjawolf0007 #8
Posted 02 December 2013 - 05:13 PM
SpoilerOkay, Todo this you must have the turtles receiveing ofcourse. Now here's a way todo it.
Transmitter
 
term.clear() 
term.setCursorPos(1,1) 
write("File: ") 
local filename = read() 

local code 
if fs.exists(filename) then 
  local f = fs.open(filename, "r") 
  code = f.readAll() 
  f.close() 
  print("Broadcasting code!") 
  rednet.broadcast(code) 
else 
  print("File didn't exist!") 
end 
Receiver
 
local id, code = rednet.receive() 
local file = fs.open("YourFile", "w") 
file.write(code) 
file.close() 

In the receiver, why is there a "w" standalone second parameter for fs.open? Also, sorry to bug you about this, but could you go through the code and explain it a little? I understand most of it… I just get a little lost while going through it. Thank you.
Edited on 02 December 2013 - 04:18 PM
LBPHacker #9
Posted 02 December 2013 - 05:26 PM
Moved the whole message over so people can see what I'm answering. This guy should get an award for hijacking.

SpoilerOkay, Todo this you must have the turtles receiveing ofcourse. Now here's a way todo it.
Transmitter

term.clear()
term.setCursorPos(1,1)
write("File: ")
local filename = read()

local code
if fs.exists(filename) then
  local f = fs.open(filename, "r")
  code = f.readAll()
  f.close()
  print("Broadcasting code!")
  rednet.broadcast(code)
else
  print("File didn't exist!")
end 
Receiver

local id, code = rednet.receive()
local file = fs.open("YourFile", "w")
file.write(code)
file.close() 

In the receiver, why is there a "w" standalone second parameter for fs.open? Also, sorry to bug you about this, but could you go through the code and explain it a little? I understand most of it… I just get a little lost while going through it. Thank you.

The "w" tells the FS API to open the file in write mode. And of course, the same thing happens in the transmitter on line 8, but fs.open gets an "r" there, which means read mode.
Bomb Bloke #10
Posted 02 December 2013 - 05:34 PM
When you fs.open() a file, you need to specify whether you intend to read data from it, or write data to it.

Edit: Ninja'd!
Edited on 03 December 2013 - 03:15 AM
Ninjawolf0007 #11
Posted 02 December 2013 - 05:49 PM
Ok, thank you. That helped a lot.

EDIT: However, what does
 local id, code 
mean exactly? It calls a local variable called id with the parameters of code? Or am I completely wrong(which wouldn't surprise me)?
Edited on 02 December 2013 - 07:49 PM
LBPHacker #12
Posted 03 December 2013 - 12:15 AM
-snip-
Nah. If there was any kind of call, you'd see at least two parentheses. local is a keyword in Lua that *surprise* localizes variables. That means when you localize a variable inside a block (will explain that later), you cannot access that variable once you get out of the block.
local x = 8 -- x is localized here, in the body of the program
if true then -- makes no sense, but it is a block nonetheless
    local y = 9 -- y is localized here, in the body of the IF block
    print(x) -- prints 8
    print(y) -- prints 9
end
print(x) -- prints 8 - we are still in the program, we are still able to access x
print(y) -- prints nothing - we're out of the IF block - y has got garbagecollected 2 lines ago, and now it isn't set at all (nil)

Blocks are those things enclosed by then and do (which start blocks), until and end (which end blocks). The so called "indentation" is about making these blocks more visible (eg. by using tabs or four (or whatever number of) spaces).

So:
local id, code
is like saying "hey, Lua, localize id and code here".
Edited on 02 December 2013 - 11:20 PM
Lyqyd #13
Posted 03 December 2013 - 12:17 AM
Threads merged. What a mess. Ninjawhatever, you really need to start one topic in Ask a Pro when you have a question instead of digging up months-old or year-old threads to post tangentially-related (at best) questions on them.