Jump to content




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

lua help

12 replies to this topic

#1 Pricey123

  • New Members
  • 10 posts

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


#2 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

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.

#3 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

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

#4 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 13 January 2013 - 12:52 PM

View PostremiX, on 13 January 2013 - 12:39 PM, said:

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.

#5 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 13 January 2013 - 12:54 PM

View PostOrwell, on 13 January 2013 - 12:52 PM, said:

View PostremiX, on 13 January 2013 - 12:39 PM, said:

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'

#6 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 13 January 2013 - 12:54 PM

View PostremiX, on 13 January 2013 - 12:54 PM, said:

View PostOrwell, on 13 January 2013 - 12:52 PM, said:

View PostremiX, on 13 January 2013 - 12:39 PM, said:

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

#7 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 13 January 2013 - 12:55 PM

View PostOrwell, on 13 January 2013 - 12:52 PM, said:

View PostremiX, on 13 January 2013 - 12:39 PM, said:

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 by TheOriginalBIT, 13 January 2013 - 12:55 PM.


#8 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 13 January 2013 - 12:55 PM

View PostOrwell, on 13 January 2013 - 12:54 PM, said:


--snip

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

Or rebooting yeah :P

#9 Pricey123

  • New Members
  • 10 posts

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

#10 ChunLing

  • Members
  • 2,027 posts

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.

#11 Pricey123

  • New Members
  • 10 posts

Posted 15 January 2013 - 07:14 AM

when i type in "term.clear" it says function: 7a2c96b8
yet i still get the error

#12 Pricey123

  • New Members
  • 10 posts

Posted 15 January 2013 - 07:37 AM

View PostLyqyd, on 15 January 2013 - 07:13 AM, said:

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

#13 ChunLing

  • Members
  • 2,027 posts

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 by ChunLing, 15 January 2013 - 06:38 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users