Jump to content




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


  • You cannot reply to this topic
5 replies to this topic

#1 NullSchritt

  • Members
  • 43 posts

Posted 22 July 2013 - 02: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


#2 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 22 July 2013 - 03: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


#3 NullSchritt

  • Members
  • 43 posts

Posted 22 July 2013 - 03:44 PM

View PostGrim Reaper, on 22 July 2013 - 03:14 PM, said:

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)

#4 NullSchritt

  • Members
  • 43 posts

Posted 22 July 2013 - 04: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.

#5 NullSchritt

  • Members
  • 43 posts

Posted 22 July 2013 - 05:40 PM

Foudn out the problem, my anti-ddos prevents automated requests except at certain subdomains, I updated them, and it works great, thanks!

#6 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 22 July 2013 - 11:51 PM

No problem! :D





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users