Jump to content




'then' expected Error


  • You cannot reply to this topic
2 replies to this topic

#1 Bambel Boar

  • Members
  • 8 posts
  • LocationUnited States

Posted 07 June 2017 - 03: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


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 07 June 2017 - 10: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.

#3 Bambel Boar

  • Members
  • 8 posts
  • LocationUnited States

Posted 07 June 2017 - 11:27 PM

View PostBomb Bloke, on 07 June 2017 - 10:20 PM, said:

"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.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users