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

bios:14: [string ".temp"]:4: '<eof>' expected

Started by JackJr, 05 October 2015 - 02:58 AM
JackJr #1
Posted 05 October 2015 - 04:58 AM
ok so i am very new to this and im trying to do something that im finding a little difficult.
No matter what i do i still get the same error code every time and none of the forums that i have checked are giving me any clues as to how to fix this.


while disk.isPresent(false) do
	  mon.print("pleas insert entery authorisation")
end
	  else
	  if disk.isPresent(true)
	  and
	  disk.hasData(true)
  end
	  then do
	  mon.print("reading card")
	  sleep(5)
   end
	  else
	  mon.print("No data on key card")
end

i have set the peripherals in a different lot of code and they do work. i checked.
Dustmuz #2
Posted 05 October 2015 - 07:17 AM
i think you got a bit to many ends


while true do
  if disk.isPresent(false) then
    mon.print("pleas insert entery authorisation")
  elseif disk.isPresent(true)and disk.hasData(true) then 
    mon.print("reading card")
    sleep(5)
  else
    mon.print("No data on key card")
  end
end

try this, and see if you get the same error
KingofGamesYami #3
Posted 05 October 2015 - 06:39 PM
Dustmuz fixed the End Of File expected error, but not the misuse of disk.isPresent, disk.hasData, nor the existence of mon.print.

disk.isPresent returns a boolean value, and does not use any parameters


if disk.isPresent() == true then
  --#disk is present
end

However this can be shortened to

if disk.isPresent() then
 --#disk is present
end
…because if statements simply require a boolean value.

disk.hasData works the same as disk.isPresent, but returns true if the disk has data.

mon.print just plain doesn't exist, mon.write does. mon.write works exactly the same as term.write, if you've ever used it. If you want to use print on a monitor, consider using term.redirect to redirect to the monitor - this will allow you to use print as normal while the output is shown on the monitor.


term.redirect( mon )
print( "This is on a monitor!" )
JackJr #4
Posted 06 October 2015 - 11:59 AM
I did what both of you recommended and i got this.

disk:3: Expected string

the code that i used after updating is as follows.
(oh and it turns out that the peripherals i setup in another code were not working. my bad)


mon=peripheral.wrap("monitor_0")
drive=peripheral.wrap("drive_0")
while true do
  if disk.isPresent() == false then
    mon.write("Please instert entery authorisation")
  elseif disk.isPresent() == true and disk.hasData() == true then
    mon.write("reading Card")
    sleep(5)
  else
    mon.write("No Data On Key Card
  end
end

P.S. i should probably mention that i am trying to do it with both the monitor and drive being connected via rednet.
Dustmuz #5
Posted 06 October 2015 - 05:31 PM
on your last mon.write.. you are missing ") at the end
Bomb Bloke #6
Posted 06 October 2015 - 10:56 PM
All disk API functions require you to specify the side of the computer that the disk drive is attached to.

Furthermore, you've got an infinite loop there, one that may never yield (see here for some notes about that). We could use the disk and disk_eject events to help with that.

Eg:

local diskSide = "drive_0"
local mon = peripheral.wrap("monitor_0")

while true do
	if not disk.hasData(diskSide) then
		mon.write("Please insert entry authorisation")
		repeat os.pullEvent("disk") until disk.hasData(diskSide)
	end
	
	if fs.exists(disk.getMountPath(diskSide) .. "/authfile.txt") then
		-- Use fs.open() to read the file:
		-- http://www.computercraft.info/wiki/Fs.open
		-- Then do whatever check you need to do to determine if it's valid or not.
		
		if <security check passed> then
			mon.write("Security passed!")
			break  -- Exit this while loop.
		end
	else
		mon.write("No Data On Key Card")
	end
	
	mon.write("Please remove invalid disk.")
	os.pullEvent("disk_eject")  -- If we reached this point then the check failed, so wait for disk removal.
end
Edited on 07 October 2015 - 03:34 AM
Waitdev_ #7
Posted 07 October 2015 - 01:27 AM
hint hint, try using notepad++ and an auto-indent, it has syntax highlighting, plugins, though no auto suggestions. but pretty useful.
HPWebcamAble #8
Posted 08 October 2015 - 04:18 AM
hint hint, try using notepad++ and an auto-indent, it has syntax highlighting, plugins, though no auto suggestions. but pretty useful.

Sublime text (Which is paid, but has an unlimited trial) actually has auto suggestions, plus a ton of extra features.

Try both NP++ and Sublime. You'll find either one is much better than the built in 'edit' program.
(The edit program is great, but only for small pro. Larger programs can be extremely difficult to manage)
JackJr #9
Posted 09 October 2015 - 09:12 AM
All disk API functions require you to specify the side of the computer that the disk drive is attached to.

Furthermore, you've got an infinite loop there, one that may never yield (see here for some notes about that). We could use the disk and disk_eject events to help with that.

But i have the drive connected over rednet. how is that supposed to work
TYKUHN2 #10
Posted 09 October 2015 - 08:24 PM
disk_0 for example is typically considered a "side" by most APIs since it is accessed in the same way as a side.