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

[Help] Nil error

Started by Sane, 19 December 2012 - 12:12 PM
Sane #1
Posted 19 December 2012 - 01:12 PM
Okay so this line of code keeps returning a nil error:

shell.run(programname)

My exact error message is:

myapi: 27 : attempt to index ? (a nil value)

Programname is part of an input of a function:


function login(programname, u1, p1)
clearall()
center("Please login to use "..programname, 1)
center("", 3)
write("Username: ")
local u = read()
center("", 5)
write("Password ")
local p = read("*")
sleep(1)

if u == (u1) and p == (p1) then
center("Login successful, please continue.", 7)
sleep(.7)
shell.run(programname) -- this is line 27
else
center("Login unsuccessful, access denied.", &)
shell.run("maingui")
end
end

I need quick help if possible, programname is called in another spot and works, but I don't know how to use it in shell.run..I just want it to boot a program that's name is the input of the function
Sammich Lord #2
Posted 19 December 2012 - 01:13 PM
The "Ask A Pro" section is for asking questions when you have problems. The "Programs" section is for released code.
immibis #3
Posted 19 December 2012 - 01:14 PM
Post the whole code of your program and the exact error message.
Also this should be in Ask a Pro, I've reported it to get a moderator's attention so they can move it. (Edit: Ninja'd)
Sane #4
Posted 19 December 2012 - 01:15 PM
I'm sorry, I didn't realize, I was in such a rush that I didn't notice, I'll update my post one sec.
Cranium #5
Posted 19 December 2012 - 01:21 PM
Mind postign the rest of the code, or at least the function? Kinda hard to troubleshoot with that little amount of info.
Sane #6
Posted 19 December 2012 - 01:21 PM
Code was posted.
Sammich Lord #7
Posted 19 December 2012 - 01:28 PM
Did you use os.loadAPI() or did you just run it? If you use os.loadAPI then the shell functions don't work.
Sane #8
Posted 19 December 2012 - 01:29 PM
Did you use os.loadAPI() or did you just run it? If you use os.loadAPI then the shell functions don't work.

I used os.loadAPI because I needed the function to be used in other programs. Is there an easier way of doing this?
Sammich Lord #9
Posted 19 December 2012 - 01:36 PM
Did you use os.loadAPI() or did you just run it? If you use os.loadAPI then the shell functions don't work.

I used os.loadAPI because I needed the function to be used in other programs. Is there an easier way of doing this?
This is how I do it:

API = {}
API.func = function()
  print("test")
end
Then you just run the script. That is how I do it.
Sane #10
Posted 19 December 2012 - 01:38 PM
Did you use os.loadAPI() or did you just run it? If you use os.loadAPI then the shell functions don't work.

I used os.loadAPI because I needed the function to be used in other programs. Is there an easier way of doing this?
This is how I do it:

API = {}
API.func = function()
  print("test")
end
Then you just run the script. That is how I do it.

Okay but where do I put that and would it just be:


API = {}
API.func = login(programname, u1, p1)
[...]
Sammich Lord #11
Posted 19 December 2012 - 01:42 PM
Did you use os.loadAPI() or did you just run it? If you use os.loadAPI then the shell functions don't work.

I used os.loadAPI because I needed the function to be used in other programs. Is there an easier way of doing this?
This is how I do it:

API = {}
API.func = function()
  print("test")
end
Then you just run the script. That is how I do it.

Okay but where do I put that and would it just be:


API = {}
API.func = login(programname, u1, p1)
[...]
Top of the file will have the APINAME = {} then after that have all your functions.
So like this:

APINAME = {}
APINAME.login = function(pname, u1, p1)
  -- Stuffz goes here
end
Sane #12
Posted 19 December 2012 - 01:44 PM
Sorry for all the confusion, so after that I can load that API from any program using:


myapi.login(pname, u1, p1)

Correct?
Sammich Lord #13
Posted 19 December 2012 - 01:45 PM
Sorry for all the confusion, so after that I can load that API from any program using:


myapi.login(pname, u1, p1)

Correct?
Yes, after you run the script that contains the functions.
Sane #14
Posted 19 December 2012 - 01:47 PM
Sorry for all the confusion, so after that I can load that API from any program using:


myapi.login(pname, u1, p1)

Correct?
Yes, after you run the script that contains the functions.

Aight thank you for all your help mate! :)/> Cheers!