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

Attempt to concatenate string and function

Started by zeronoashaen, 16 January 2014 - 11:57 AM
zeronoashaen #1
Posted 16 January 2014 - 12:57 PM
I am trying to get the computers on my server to auto boot a specific script housed in a specific folder. I tried setting it up in the bios.lua, and the startup file within the rom but it does not seem to work. When I started digging into it I found I got the above message. Here is the code that I have as of right now:


overridesPath = "/rom/<folder>/overrides"
--folder holds files with a single word on line 1, word is the name of the program I want to run
overScriptsPath = "/rom/<folder>/scripts"
--location of all scripts that will run
customScriptsExists = fs.exists(overridesPath..os.getComputerID())

if customScriptExists then
   local customScripts = io.open(overridesPath..os.getComputerID(), "r")
   local scriptToRun = customScripts:read()
   while scriptToRun do
	  if (fs.exists(overScriptsPath..scriptToRun)) then
		 os.run( {}, overScriptsPath..scriptToRun)
	  else
		 print("Script "..scriptToRun.." for ID "..os.getComputerID().." does not exist. Please contact an Admin." )
	  end
   end
end

The error comes up on this line


customScriptsExists = fs.exists(overridesPath..os.getComputerID())

Any help would be greatly appreciated.

EDIT: forgot to say I'm using ComputerCraft 1.58
Edited on 16 January 2014 - 11:59 AM
Lyqyd #2
Posted 16 January 2014 - 01:01 PM
Did you copy and paste this or re-type it? You probably don't have the parentheses on os.computerID() in the actual code.
zeronoashaen #3
Posted 16 January 2014 - 01:33 PM
I copied this directly from my code and then edited out some of it. The parenthesis are there in my code.
Lyqyd #4
Posted 16 January 2014 - 02:44 PM
Please directly paste the full code and the full error message.
zeronoashaen #5
Posted 16 January 2014 - 03:31 PM
Alright, I don't really know what I did differently, but the original error message I was getting is no longer coming up. However this is the startup file that comes with computercraft1.58, I figured this was the best place to put my custom startup script it.


--**********Outlandcraft Boot**********
overridesPath = "/rom/<SECRET>/overrides"
overScriptsPath = "/rom/<SECRET>/scripts"
customScriptsExists = fs.exists(overridesPath..os.getComputerID())

if customScripstExists then
   local customScripts = io.open(overridesPath..os.getComputerID(), "r")
   local scriptToRun = customScripts:read()
   while scriptToRun do
	  if (fs.exists(overScriptsPath..scriptToRun)) then
		 os.run( {}, overScriptsPath..scriptToRun)
	  else
		 print("Script "..scriptToRun.." for ID "..os.getComputerID().." does not exist. Please contact an Admiral." )
	  end
	  scriptToRun = customScript:read()
   end
end


local sPath = ".:/rom/programs"
if turtle then
   sPath = sPath..":/rom/programs/turtle"
else
   sPath = sPath..":/rom/programs/computer"
end
if http then
   sPath = sPath..":/rom/programs/http"
end
if term.isColor() then
   sPath = sPath..":/rom/programs/color"
end

shell.setPath( sPath )
help.setPath( "/rom/help" )

shell.setAlias( "ls", "list" )
shell.setAlias( "dir", "list" )
shell.setAlias( "cp", "copy" )
shell.setAlias( "mv", "move" )
shell.setAlias( "rm", "delete" )
shell.setAlias( "preview", "edit" )

if fs.exists( "/rom/autorun" ) and fs.isDir( "/rom/autorun" ) then
   local tFiles = fs.list( "/rom/autorun" )
   table.sort( tFiles )
   for n, sFile in ipairs( tFiles ) do
	  if string.sub( sFile, 1, 1 ) ~= "." then
		 local sPath = "/rom/autorun/"..sFile
		 if not fs.isDir( sPath ) then
			shell.run( sPath )
		 end
	  end
   end
end

This code did not work so when I went into lua and started trying to debug what exactly is not working I found that it is not finding the file (in this case just named 4 since that is the ID of the computer) in the path above. Could the fact that I made the file hidden by putting a "." in front matter, even though I put the actual folder name including the "." up in the beginning.
Edited on 16 January 2014 - 02:53 PM
zeronoashaen #6
Posted 16 January 2014 - 04:29 PM
I have fixed the code, if anyone wants it here it is stripped down:
overridesPath = "/rom/overrides/overrides/"
overScriptsPath = "/rom/overrides/scripts/"
customScriptsExists = fs.exists(overridesPath..os.getComputerID())

if customScriptsExists then
local customScripts = io.open(overridesPath..os.getComputerID(), "r")
local scriptToRun = customScripts:read()
while scriptToRun do
if (fs.exists(overScriptsPath..scriptToRun)) then
os.run( {}, overScriptsPath..scriptToRun)
else
print("Script "..scriptToRun.." for ID "..os.getComputerID().." does not exist. Please contact an Admiral." )
end
end
end
Edited on 16 January 2014 - 03:30 PM