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

Coding Error? (Attempt To Index ? A Nil Value)

Started by NullSchritt, 22 July 2013 - 01:43 PM
NullSchritt #1
Posted 22 July 2013 - 03:43 PM
Hello, I have been coding a system that allows computers to be remotely controlled from other computers in the game, I am on my final piece of code, however I keep seeming to get one error after another, and I can't see anything wrong with my code at this point but I still get the following error

"STARTUP:5: attempt to index ? (a nil value)"

Could anyone take a look at my code and tell me what's wrong?

I am still rather new to LUA and could use a more proficient set of eyes, as always, thanks to this extremely helpful community.


cb = peripheral.wrap("bottom")
while true do
content = http.get("http://projectbuilder.info/fetch.php?cmd=page&ID=GATENET")
s = content.readAll()
if s == "" then
sleep(2)
else
GID, origin, dest = string.match(s, "(%d+)|(%a+)|(%a+)")
content = http.get("http://projectbuilder.info/fetch.php?cmd=page&ID=gatereqdel&GID="..GID)
cb.setCommand("gate activate " .. origin .. " " .. dest)
cb.runCommand()
end
sleep(2)
end
Grim Reaper #2
Posted 22 July 2013 - 04:14 PM
Make sure that the content handle is not nil. I was trying to get that webpage using CC earlier, but I couldn't seem to be able to do that. I can view it fine in browser, however.

Try this:


local content = http.get ("http://projectbuilder.info/fetch.php?cmd=page&ID=GATENET")

if content then
-- Insert your code here to parse the content and such.
else
  printError ("There was a problem fetching the web page.")
end
NullSchritt #3
Posted 22 July 2013 - 04:44 PM
Make sure that the content handle is not nil. I was trying to get that webpage using CC earlier, but I couldn't seem to be able to do that. I can view it fine in browser, however.

Try this:


local content = http.get ("http://projectbuilder.info/fetch.php?cmd=page&ID=GATENET")

if content then
-- Insert your code here to parse the content and such.
else
  printError ("There was a problem fetching the web page.")
end
I think this may have corrected the problem, let me run some tests to find out. (it's not erroring out anymore)
NullSchritt #4
Posted 22 July 2013 - 05:52 PM
No, this did not fix the problem it just stopped the program from crashing, any ideas on why comptuercraft isn't getting the page properly? It gets all the other pages off my site properly.
NullSchritt #5
Posted 22 July 2013 - 06:40 PM
Foudn out the problem, my anti-ddos prevents automated requests except at certain subdomains, I updated them, and it works great, thanks!
Grim Reaper #6
Posted 23 July 2013 - 12:51 AM
No problem! :D/>