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

trying to connect to world wide web

Started by mr_chicken12345, 29 June 2012 - 05:55 PM
mr_chicken12345 #1
Posted 29 June 2012 - 07:55 PM
i am trying to make a program that indexes a website and then reads and executes a program on that site but i keep getting a examplecode:9: attempt to index? (a nil value)
here is the code:


if http == nil then
print('Please enable the http api.')
print('Look for enableAPI_http=0 in .minecraft/config/mod_ComputerCraft and change the zero to a one and then restart Minecraft')
return false
end

urlBase = 'http://examplesite.com'

package.get(file)
package.load(file)
shell.run(file)

what did i do wrong?
MysticT #2
Posted 29 June 2012 - 08:47 PM
This lines are the problem:

package.get(file)
package.load(file)
package is not defined. If you'r trying to use the lua package "api", it's disabled in CC.
If it's a custom api, then you have to load it with os.loadAPI.
mr_chicken12345 #3
Posted 29 June 2012 - 09:18 PM
thanks!
that helped
mr_chicken12345 #4
Posted 29 June 2012 - 09:22 PM
wait, that world be

os.Load(file)?
MysticT #5
Posted 29 June 2012 - 10:19 PM
No, there's no such function.
If you want to load an api, use:

os.loadAPI("<Path to the API file>")
then use it like:

<ApiName>.<Function>()
where ApiName is the name of the api file.

To get the file from the web, use the http api:

local file = http.get(<URL>)
if file then
  local contents = file.readAll()
  -- do whatever you want with the contents, like saving it to a file
  file.close()
end
mr_chicken12345 #6
Posted 29 June 2012 - 11:15 PM
thanks!