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

[Error] http.get '=' expected

Started by Simon, 04 March 2013 - 09:15 AM
Simon #1
Posted 04 March 2013 - 10:15 AM
I have no idea…

bios:338: [string "paste"]:6: '=' expected



local tArgs = { ... }
local sCode = tArgs[1]
local sFile = tArgs[2]
local sPath = shell.resolve( sFile )

local response = http.get("http://pastebin.com/raw.php?i=" ..sCode)

if response then
failed = false
local sResponse = response.readAll()
response.close()

local file = fs.open( sPath, "w" )
file.write( sResponse )
file.close()
print( "Downloaded as "..sFile )

else
print( "Failed." )
failed = true
fail()
end

failed and fail are already created in the startup program btw

Thanks in advance wonderful forum members
Shnupbups #2
Posted 04 March 2013 - 10:21 AM
Have you got the HTTP API as true in your config? That's the only explanation I can think of. It's off by default so you have to turn it on manually. Go into:
%appdata%/.minecraft/config/ComputerCraft.cfg
and there should be a line with:

# Enable the "http" API on Computers
    B:enableAPI_http=false
Set the 'false' to true and it should work.
SuicidalSTDz #3
Posted 04 March 2013 - 01:51 PM
You could also add a check to ensure http is enabled like so:

if not http then
  return error("Http is not enabled!")
end

Pretty nice in some occasions.

Also, why are you making a pastebin program when CC already has one?
theoriginalbit #4
Posted 04 March 2013 - 02:03 PM
Also, why are you making a pastebin program when CC already has one?
Have you seen my "Program d" … it was my first http program, its a good starting point … just like door locks are the starting point of anything else …
SuicidalSTDz #5
Posted 04 March 2013 - 04:06 PM
Also, why are you making a pastebin program when CC already has one?
Have you seen my "Program d" … it was my first http program, its a good starting point … just like door locks are the starting point of anything else …
Hmm, I guess you are right. ( Like the program btw :P/> )

Side Note:You seem to counter everything I have to say! Let the games begin :D/> (Even though challenging a Semi-Professional ComputerCrafter would call for the highest degree of sorcery)
immibis #6
Posted 04 March 2013 - 05:20 PM
This error message would NOT be caused by HTTP being disabled. I'm on my phone so I can't see the code to tell you the real problem.
SuicidalSTDz #7
Posted 04 March 2013 - 05:35 PM
This error message would NOT be caused by HTTP being disabled. I'm on my phone so I can't see the code to tell you the real problem.
It seems to be erroring at line 6 which is where he defines the variable "response" The following is the exact same code as he posted, line for line.


local tArgs = { … }
local sCode = tArgs[1]
local sFile = tArgs[2]
local sPath = shell.resolve( sFile )

local response = http.get("http://pastebin.com/raw.php?i=" ..sCode)

if response then
failed = false
local sResponse = response.readAll()
response.close()

local file = fs.open( sPath, "w" )
file.write( sResponse )
file.close()
print( "Downloaded as "..sFile )

else
print( "Failed." )
failed = true
fail()
end
immibis #8
Posted 04 March 2013 - 08:04 PM
With http:

paste:21: attempt to call nil
Without http:

paste:6: attempt to index '?' (a nil value)

Conclusion: The code in the OP is different from the code he was actually trying to run.
Dlcruz129 #9
Posted 04 March 2013 - 08:06 PM
In-game: type "pastebin put [filename]"
As immibis said, you copied the code wrong.
Engineer #10
Posted 05 March 2013 - 06:41 AM
do you have the function fail defined?

if not, then you should this above your code


function fail()
   -- What you want to do
end

But as I am typing this, dont you want to use error()? If this has been run directly from the shell, then you wont need the error() or fail() except if you want to do something else with fail()

I hope I've helped you,

Engineer
Simon #11
Posted 05 March 2013 - 07:03 AM
Hmm, it works now. Creepy.

Edit: Someone was messing with me on my server -_-/>