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

Attempt to index ? (A nil value)

Started by SGunner2014, 23 September 2014 - 07:52 PM
SGunner2014 #1
Posted 23 September 2014 - 09:52 PM
I have a feeling that I'm being really derpy here, but when I try to launch my program from the start screen I made, it draws up this error on line 9 of this file. I can't seem to figure out why it does this, however. If I try to launch it from the shell, it works fine though.


while true do
term.clear()
bground = paintutils.loadImage("os8/assets/wbground.nfp")
paintutils.drawImage(bground,1,1)
term.setCursorPos(1,1)
term.setTextColor(colors.black)
term.setBackgroundColor(colors.white)
if fs.exists("os8/assets/appStore.list") == true then fs.delete("os8/assets/appStore.list") end
shell.run("pastebin get y1RAbu4D os8/assets/appStore.list") --#It says it gets the error here
term.clear()
print("APP STORE - APP LIST")
local h = fs.open("os8/assets/appStore.list", "r")
local app1Line1 = h.readLine()
local app1Line2 = h.readLine()
local app1Line3 = h.readLine()
local app2Line1 = h.readLine()
local app2Line2 = h.readLine()
local app2Line3 = h.readLine()
print("App name: "..app1Line1)
print("Made by: "..app1Line2)
print("LAUNCH")
print("")
print("App name: "..app2Line1)
print("Made by: "..app2Line2)
print("LAUNCH")
local event, button, x, y = os.pullEvent("mouse_click")
if button == 1 and x>=1 and x<=6 and y==4 then
  local exist = fs.exists("os8/apps/"..app1Line2..".app")
  if exist == true then
	local tabID = multishell.launch({}, "os8/apps/"..app1Line2..".app")
	multishell.setTitle(tabID, app1Line1)
	h.close()
	multishell.setFocus(tabID)
  elseif exist == false then
	term.clear()
	paintutils.drawImage(bground,1,1)
	term.setCursorPos(1,1)
	print(app1line1)
	print("is not installed. Would you like to install?")
	term.setCursorPos(20,9)
	print("YES")
	term.setCursorPos(20,9)
	print("NO")
	while true do
	local event, button, x, y = os.pullEvent("mouse_click")
	if button == 1 and x>=20 and x<=22 and y==9 then
	  shell.run("pastebin get "..app1Line3.." "..app1Line3)
	  term.clear()
	  paintutils.drawImage(bground,1,1)
	  term.setCursorPos(1,1)
	  write("D")
	  sleep(0.1)
	  write("o")
	  sleep(0.1)
	  write("n")
	  sleep(0.1)
	  write("e")
	  sleep(2)
	  break
	end
	end
  end
end
end

Any suggestions?

Thanks,
- Sam

PS I can list the code for the start screen if needed.
Edited on 23 September 2014 - 07:53 PM
Bomb Bloke #2
Posted 23 September 2014 - 10:15 PM
Presumably your start screen script is using os.run() but isn't setting the desired environment. You may find it easier to use shell.run() instead.
SGunner2014 #3
Posted 23 September 2014 - 10:20 PM
Presumably your start screen script is using os.run() but isn't setting the desired environment. You may find it easier to use shell.run() instead.

My start screen script is using multishell.launch() to launch the program. I'm using this so I can integrate multitasking into my OS.

Any ideas?

Thanks,
- Sam
Lyqyd #4
Posted 23 September 2014 - 11:26 PM
The problem Bomb Bloke mentioned is the issue. Multishell's launch function requires you to pass the environment table, so if you're not passing the correct environment, the shell "API" won't be present. Please post your start screen script.
SGunner2014 #5
Posted 24 September 2014 - 07:49 PM
Here's the startup script:


  local tabID = multishell.launch({}, "os8/assets/appStore.app")
  multishell.setTitle(tabID, "App Store")
  multishell.setFocus(tabID)
end
end
end

P.S Please note that the ends are part of a bigger picture.

EDIT: Posted the wrong bit of code
Edited on 24 September 2014 - 05:52 PM
Bomb Bloke #6
Posted 24 September 2014 - 11:56 PM
Give this a try:

local tabID = multishell.launch({["shell"] = shell}, "os8/assets/appStore.app")

This adds a pointer to the "shell" table to the environment of the launched script.
Lyqyd #7
Posted 25 September 2014 - 12:59 AM
The multishell "API" should also be included when providing complete environments to programs:


local tabID = multishell.launch({shell = shell, multishell = multishell}, "os8/assets/appStore.app")
SGunner2014 #8
Posted 25 September 2014 - 04:29 PM
Okay, thanks guys, I'll give that a go now :)/>

EDIT: Okay, tried it and it works. Thanks once again :)/>
Edited on 25 September 2014 - 02:41 PM