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

[Lua][Error] startup:2: attempt to call nil

Started by Pricey123, 13 January 2013 - 11:00 AM
Pricey123 #1
Posted 13 January 2013 - 12:00 PM
I Keep on getting errors with this code but im not sure whats going wrong with it i am following a tutorial but its not working
any help much appreciated

os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
print("This is a password server. There is no user interaction here.")
print("Please find a computer and login there.")
local firstCycle = true
local validSender = false
local modemSide = "left"
local valid = false
users = {"username1", "username2" }
passwords = {"password1", "password2" }
senders = { 1, 2, 3, 4 }
function bootUp()
rednet.open("right")
end
while true do
validSender = false
if firstCycle then
  bootUp()
  firstCycle = false
end
senderId, message, distance = rednet.receive()
for i,v in ipairs(senders) do
  if v == senderId then
   validSender = true
   break
  end
end
if validSender then
  for i,v in ipairs(users) do
   if message == v then
    valid = true
    password = passwords[i]
    break
   else
    valid = false
   end
  end
  if valid then
   rednet.send(senderId, password, true)
  end
end
end
Orwell #2
Posted 13 January 2013 - 12:38 PM
Did you run this on startup or by running it from the shell? I can't see how this is possible without overriding some variables (like term in this case). The same applies for the other post that linked here.
remiX #3
Posted 13 January 2013 - 12:39 PM
I don't see a reason why it's giving an error, especially for line 2…

Try placing a new computer and test? Maybe you overwrote the term api at some point
Orwell #4
Posted 13 January 2013 - 12:52 PM
I don't see a reason why it's giving an error, especially for line 2…

Try placing a new computer and test? Maybe you overwrote the term api at some point
Altering the actual term api could only be done through editing the ROM and then replacing the computer shouldn't fix that either.
Either it will be fixed on a fresh boot (a CC computer boot, that is), or the apis in the ROM directory haven been altered (deleted/were never there) or there's something really strange going on.

Edit: term.clear() isn't even lua side, so I don't think it's option 2.
remiX #5
Posted 13 January 2013 - 12:54 PM
I don't see a reason why it's giving an error, especially for line 2…

Try placing a new computer and test? Maybe you overwrote the term api at some point
Altering the actual term api could only be done through editing the ROM and then replacing the computer shouldn't fix that either.
Either it will be fixed on a fresh boot (a CC computer boot, that is), or the apis in the ROM directory haven been altered (deleted/were never there) or there's something really strange going on.

I mean if he did:


term = "hello"

I meant that when I said 'overwrote'
Orwell #6
Posted 13 January 2013 - 12:54 PM
I don't see a reason why it's giving an error, especially for line 2…

Try placing a new computer and test? Maybe you overwrote the term api at some point
Altering the actual term api could only be done through editing the ROM and then replacing the computer shouldn't fix that either.
Either it will be fixed on a fresh boot (a CC computer boot, that is), or the apis in the ROM directory haven been altered (deleted/were never there) or there's something really strange going on.

I mean if he did:


term = "hello"

I meant that when I said 'overwrote'
I supposed that. Then still, rebooting would give the same effect as replacing. :P/>
theoriginalbit #7
Posted 13 January 2013 - 12:55 PM
I don't see a reason why it's giving an error, especially for line 2…

Try placing a new computer and test? Maybe you overwrote the term api at some point
Altering the actual term api could only be done through editing the ROM and then replacing the computer shouldn't fix that either.
Either it will be fixed on a fresh boot (a CC computer boot, that is), or the apis in the ROM directory haven been altered (deleted/were never there) or there's something really strange going on.

Edit: term.clear() isn't even lua side, so I don't think it's option 2.
I've seen some API's override the term api with their own, could be possible someone used one on that computer and it did something like this


term.clear = nil
term.clear()
That would cause a nil error…

EDIT: And in the time it takes to type this… 3 posts… lol
Edited on 13 January 2013 - 11:55 AM
remiX #8
Posted 13 January 2013 - 12:55 PM
–snip

I supposed that. Then still, rebooting would give the same effect as replacing. :P/>/>

Or rebooting yeah :P/>
Pricey123 #9
Posted 13 January 2013 - 08:38 PM
Hey thanks for the replies
I have tried rebooting my computer that hasnt seem to work
I am using this on startup so im not sure
Sorry about this im not very good at ComputerCraft
ChunLing #10
Posted 14 January 2013 - 01:28 PM
Use the edit program to edit startup, and copy/paste line 2.

If line 2 as displayed in edit is the one with the term.clear() call, then exit edit and start lua. Enter "type(term.clear)" and see what it gives you (it should say its a function).

Then try the startup program again to make sure the error is still happening.
Pricey123 #11
Posted 15 January 2013 - 07:14 AM
when i type in "term.clear" it says function: 7a2c96b8
yet i still get the error
Pricey123 #12
Posted 15 January 2013 - 07:37 AM
Did you retype the program here or copy and paste it? Be sure the actual program has rednet.receive and not rednet.recieve.

That seems to have fixed it
i spelt it incorrectly
ChunLing #13
Posted 15 January 2013 - 05:45 PM


Okay, spotting minor spelling errors in the version of code that wasn't posted is a whole different level of error-checking. :huh:/> (As Neo said, "whoa")

Because of the post in the related thread, I took the liberty of restructuring this code to be a little easier to follow:
os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
print("This is a password server. There is no user interaction here.")
print("Please find a computer and login there.")
passwords = {username1="password1",username2="password2" }
senders = {[1]=true,[2]=true,[3]=true,[4]=true,}
rednet.open("right")
while true do
    senderId, message, distance = rednet.receive()
    if senders[senderId] and passwords[message] then
        rednet.send(senderId,passwords[message], true)
    end
end
This arranges the tables to be indexed so that you can usefully check to see if a given index exists, eliminating most of the conditional checks. It should do essentially what you were doing before, but perhaps a bit more reliably.
Edited on 15 January 2013 - 05:38 PM