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

Shell:80: expected string, got nil

Started by Emma, 28 June 2013 - 08:14 PM
Emma #1
Posted 28 June 2013 - 10:14 PM
I am trying to write an updater script for my program but when I run it i get "shell:80: expected string, got nil" can anyone help me?



client="Update Client"
server="Update Server"
self="Update Self"

clientsel="* Update Client *"
serversel="* Update Server *"
selfsel="* Update Self *"

uptx="Checking for update..."
futx="Found Update! Press Y to update or N to cancel"
lvtx="Script already at latest version!"
cutx="Updating..."
catx="Canceled!"

cuctx="Updated!"


clientcode="g7AmTvM8"
servercode="43NXRhFi"
selfcode="6UwqyDkP"

selected=1

shell.run("clear")

screenx,screeny=term.getSize()

function draw()
  shell.run("clear")
  if selected==1 then
	term.setCursorPos((screenx/2)-(string.len(clientsel)/2),screeny/3-3)
	write(clientsel)
	term.setCursorPos((screenx/2)-(string.len(server)/2),screeny/3*2-3)
	write(server)
	term.setCursorPos((screenx/2)-(string.len(self)/2),screeny/3*3-3)
	write(self)
  else if selected==2 then
	term.setCursorPos((screenx/2)-(string.len(client)/2),screeny/3-3)
	write(client)
	term.setCursorPos((screenx/2)-(string.len(serversel)/2),screeny/3*2-3)
	write(serversel)
	term.setCursorPos((screenx/2)-(string.len(self)/2),screeny/3*3-3)
	write(self)
  else if selected==3 then
	term.setCursorPos((screenx/2)-(string.len(client)/2),screeny/3-3)
	write(client)
	term.setCursorPos((screenx/2)-(string.len(server)/2),screeny/3*2-3)
	write(server)
	term.setCursorPos((screenx/2)-(string.len(selfsel)/2),screeny/3*3-3)
	write(selfsel)
  end
  end
  end
end

draw()

function localv()
  shell.resolve()
end

function checkForUpdate(pbcode,scname)
  atf=false
  if fs.exists(localv().."/"..scname) then
	h=http.get("http://pastebin.com/raw.php?i="..pbcode)
	hsc=h.readAll()
	c=fs.open(localv(scname),"a")
	csc=c.readAll()
	if hsc==csc then atf=false else atf=true end
	h.close()
	c.close()
	return atf
  else
	return true
  end
end

function updateclient()
  shell.run("clear")
  term.setCursorPos((screenx/2)-(string.len(uptx)/2),screeny/2)
  write(uptx)
  if checkForUpdate(clientcode,chat) then
	shell.run("clear")
	term.setCursorPos((screenx/2)-(string.len(futx)/2),screeny/2)
	write(futx)
	while slup==nil do
	  e,par1=os.pullEvent()
	  if e == "key" then
		if tostring(par1) == "21" then
		  shell.run("clear")
		  term.setCursorPos((screenx/2)-(string.len(cutx)/2),screeny/2)
		  write(cutx)
  h=http.get("http://pastebin.com/raw.php?i=g7AmTvM8")
  hsc=h.readAll()
  c=fs.open(localv("chat"),"w")
  c.write(hsc)
  h.close()
  c.close()
  shell.run("clear")
  term.setCursorPos((screenx/2)-(string.len(cuctx)/2),screeny/2)
  write(cuctx)
		  sleep(2.5)
		  return
		else if tostring(par1) == "49" then
		  shell.run("clear")
		  term.setCursorPos((screenx/2)-(string.len(catx)/2),screeny/2)
		  write(catx)
		  sleep(2.5)
		  return
		end
	  end
	end
	end
  else
	shell.run("clear")
	term.setCursorPos((screenx/2)-(string.len(lvtx)/2),screeny/2)
	write(lvtx)
  end
end

function updateserver()
  shell.run("clear")
  term.setCursorPos((screenx/2)-(string.len(uptx)/2),screeny/2)
  write(uptx)
  if checkForUpdate(servercode,server) then
	shell.run("clear")
	term.setCursorPos((screenx/2)-(string.len(futx)/2),screeny/2)
	write(futx)
	while slup==nil do
	  e,par1=os.pullEvent()
	  if e == "key" then
		if tostring(par1) == "21" then
		  shell.run("clear")
		  term.setCursorPos((screenx/2)-(string.len(cutx)/2),screeny/2)
		  write(cutx)
  h=http.get("http://pastebin.com/raw.php?i=43NXRhFi")
  hsc=h.readAll()
  c=fs.open(localv("server"),"w")
  c.write(hsc)
  h.close()
  c.close()
  shell.run("clear")
  term.setCursorPos((screenx/2)-(string.len(cuctx)/2),screeny/2)
  write(cuctx)
		  sleep(2.5)
		  return
		else if tostring(par1) == "49" then
		  shell.run("clear")
		  term.setCursorPos((screenx/2)-(string.len(catx)/2),screeny/2)
		  write(catx)
		  sleep(2.5)
		  return
		end
	  end
	end
	end
  else
	shell.run("clear")
	term.setCursorPos((screenx/2)-(string.len(lvtx)/2),screeny/2)
	write(lvtx)
  end
end

function updateself()
  shell.run("clear")
  term.setCursorPos((screenx/2)-(string.len(uptx)/2),screeny/2)
  write(uptx)
  if checkForUpdate(selfcode,chat) then
	shell.run("clear")
	term.setCursorPos((screenx/2)-(string.len(futx)/2),screeny/2)
	write(futx)
	while slup==nil do
	  e,par1=os.pullEvent()
	  if e == "key" then
		if tostring(par1) == "21" then
		  shell.run("clear")
		  term.setCursorPos((screenx/2)-(string.len(cutx)/2),screeny/2)
		  write(cutx)
  h=http.get("http://pastebin.com/raw.php?i=6UwqyDkP")
  hsc=h.readAll()
  c=fs.open(localv("updater"),"w")
  c.write(hsc)
  h.close()
  c.close()
  shell.run("clear")
  term.setCursorPos((screenx/2)-(string.len(cuctx)/2),screeny/2)
  write(cuctx)
		  sleep(2.5)
		  return
		else if tostring(par1) == "49" then
		  shell.run("clear")
		  term.setCursorPos((screenx/2)-(string.len(catx)/2),screeny/2)
		  write(catx)
		  sleep(2.5)
		  return
		end
	  end
	end
	end
  else
	shell.run("clear")
	term.setCursorPos((screenx/2)-(string.len(lvtx)/2),screeny/2)
	write(lvtx)
  end
end

while true do
  e,par1=os.pullEvent()
  if e=="key" then
  if tostring(par1)=="205" or tostring(par1)=="208" then
	if selected==3 then
	  selected=1
	else
	  selected=selected+1
	end
  end
  if tostring(par1)=="200" or tostring(par1)=="203" then
	if selected==1 then
	  selected=3
	else
	  selected=selected-1
	end
  end
  if tostring(par1)=="28" then
	if selected==1 then
	  updateclient()
	else if selected==2 then
	  updateserver()
	else if selected==3 then
	  updateself()
	end
	end
  end
  draw()
  sleep(0.25)
  end
end
end
Grim Reaper #2
Posted 29 June 2013 - 12:36 AM

shell.resolve()

Requires a string which is the path of the program/directory you're trying to resolve.
Since you're calling it in 'localv()' without an argument, the shell.resolve function is trying to call substring on a nil value and therefore is trying to index an object (table) which is nil.

Here is the full code for the shell.resolve function:

function shell.resolve( _sPath )
  local sStartChar = string.sub( _sPath, 1, 1 )
	 if sStartChar == "/" or sStartChar == "\\" then
		return fs.combine( "", _sPath )
	 else
		return fs.combine( sDir, _sPath )
	 end
end
Emma #3
Posted 29 June 2013 - 11:50 AM

shell.resolve()

Requires a string which is the path of the program/directory your trying to resolve.
Since you're calling it in 'localv()' without an argument, the shell.resolve function is trying to call substring on a nil value and therefore is trying to index an object (table) which is nil.

Here is the full code for the shell.resolve function:

function shell.resolve( _sPath )
  local sStartChar = string.sub( _sPath, 1, 1 )
	 if sStartChar == "/" or sStartChar == "\\" then
		return fs.combine( "", _sPath )
	 else
		return fs.combine( sDir, _sPath )
	 end
end

Thanks so much for spotting my typo, it would have taken me a long time to figure that out! :)/>