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

'then' expected Error

Started by Bambel Boar, 07 June 2017 - 02:45 PM
Bambel Boar #1
Posted 07 June 2017 - 04:45 PM
For the love of my life, I can't find what needs to be done to fix this code. My program is supposed to replicate itself to a disk if a disk is present, and do nothing if there is no disk present. If a disk is present and a startup file exists it will not replicate itself to the disk. I checked for any errors with the presence of "end" statements as there are a lot of them in my code and they are a little messy. I placed a disk drive with an empty floppy disk on the right side of my advanced computer, ran the code inside of the edit program, and I received this error:

bios:14: [string ".temp"]:20: 'then' expected
I looked at line 20 and there is no missing "then" and I checked according to the "Read This Post Before Asking Questions" thread and I can still not find an error.

Here is my code:

print("Initializing...")
os.pullEvent = os.pullEventRaw
-- Just in case you pressed Ctrl T while it's still running because stopping in the middle of this program would confuse me if I ever had to manage the aftermath.
print("Replicating...")
side = {"top","bottom","left","right","up","down","front","back"}
-- For defining the names of sides to a variable then below it checks for a disk NOT containing a startup file
i = nil
for i = 1,#side do
  if peripheral.getType(side[i]) == "drive" then
	if disk.isPresent(side[i]) then
	  diskf = fs.list("/disk")

	  for i = 1,#diskf do
		if diskf[i] != "startup" then
		  startupExists = false
		  i = i + 1
		else
		  startupExists = true
		end  
		if startupExists == true then
		  i = #diskf
		end
	  end
	  fs.copy("/spreader","/disk/startup") -- This is creating a startup file with the contents of this program, "spreader"
	end
  end
end
Bomb Bloke #2
Posted 07 June 2017 - 11:20 PM
"X expected" means you've put something that isn't acceptable where X could go. In this case, you've stuck != in line 20, where you meant to use ~=.

fs.list() isn't appropriate for file existence checks; use fs.exists() instead.
Bambel Boar #3
Posted 08 June 2017 - 12:27 AM
"X expected" means you've put something that isn't acceptable where X could go. In this case, you've stuck != in line 20, where you meant to use ~=.

fs.list() isn't appropriate for file existence checks; use fs.exists() instead.
Thanks! This was very helpful. Issue was resolved.