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

Peripherals

Started by darcline, 05 April 2015 - 03:04 PM
darcline #1
Posted 05 April 2015 - 05:04 PM
Hello programmers,

i can a little bit lua but not enough for this :D/>

i have bounded 2 disk drives with an cable modem,

the problem is, how can i read them for the disk.isPresent command over rednet ?

i try to learn and understand rednet but not so easy for me :D/>
Lyqyd #2
Posted 05 April 2015 - 05:09 PM
When you right-clicked to activate the modems attached to the disk drives, it generated a chat message saying something like "drive_0 connected to the network". Use that network name as the peripheral side name. Since the disk API functions can use a side name directly, it might look like this:


if disk.isPresent("drive_0") then
  --# do stuff
end
darcline #3
Posted 05 April 2015 - 05:12 PM
ah ok and have i to use the rednet.open() on at the programm ?

the hardware connecten had to be on but what is with the software ?
Creator #4
Posted 05 April 2015 - 05:21 PM
Nope, you dont use rednet.

You simply do this:

local file = fs.open("disk","r")
where disk can also be disk2 depending on the number of the disk.
darcline #5
Posted 05 April 2015 - 05:24 PM
ok thanks i try it now,

when it not works i post it here ;)/>

thanks for the first part
darcline #6
Posted 05 April 2015 - 05:51 PM
ok now i have a problem i get an syntax error at line 23 and line 22 the same
term.clear()

drive1 = ("drive_0")-- Disk Drive 1
drive2 = ("drive_1")-- Disk Drive 2
disklabel = ("Securitycard")-- Disk Label Needed
Securitylp = ("Level 1 File")-- Security Level File Needed on Keycard





while true do

if (disk.isPresent(drive1) or (drive2)) then-- check if keycard in drive 1 or drive 2
   current_disklabel = disk.getLabel("disk") or ("disk2")-- get disklabel from disk
   if (current_disklabel == disklabel) then-- if disklabel = Needed disk Label
	 local file = fs.open("disk", "r")-- search for Security File
	 if file == Securitylp then-- when security file exist then give redstone signal
		redstone.setOutput("bottom", true)
		disk.eject("disk") --put Keycard out
		sleep(10) --wait 10 seconds and set redstone signal 0
		redstone.setOutput("bottom", false)
	 else (print("false"))-- restart computer or repeat the loop
   else (print("false"))-- restart computer or repeat the loop
end
end	  

so there where is print("false") i wnat to repeat the loop but i dont now how ?
the next think is i hope it works :D/>
very long time not written any programs in lua or other languages.
Edited on 05 April 2015 - 03:53 PM
Creator #7
Posted 05 April 2015 - 06:00 PM
term.clear() –OK

drive1 = ("drive_0")– Disk Drive 1 – string are declared like this stringname = "blahblah"
drive2 = ("drive_1")– Disk Drive 2
disklabel = ("Securitycard")– Disk Label Needed
Securitylp = ("Level 1 File")– Security Level File Needed on Keycard





while true do

if (disk.isPresent(drive1) or (drive2)) then– check if keycard in drive 1 or drive 2 – make it ("drive") or ("drive2") drive1 is only disk
current_disklabel = disk.getLabel("disk") or ("disk2")– get disklabel from disk –disk.getLabel("disk") or disk.getLabel("disk2")
if (current_disklabel == disklabel) then– if disklabel = Needed disk Label –
local file = fs.open("disk", "r")– search for Security File –s.open("diskWhaeverNumber/file", "r") use disk is present to see which disk is present
if file == Securitylp then– when security file exist then give redstone signal – you may mean if file.readAll() == Securitylp
redstone.setOutput("bottom", true) – file.close()
disk.eject("disk") –put Keycard out – check which disk
sleep(10) –wait 10 seconds and set redstone signal 0
redstone.setOutput("bottom", false)
else (print("false"))– restart computer or repeat the loop
else (print("false"))– restart computer or repeat the loop
end
end

Hope I helped you
darcline #8
Posted 05 April 2015 - 06:13 PM
ahm ok moment :D/> too much comments

it can only be one keycard at a time, why should i check which disk it put out ?

thanks for the file close i have forget it,

but the syntax error ist still allive
darcline #9
Posted 05 April 2015 - 07:45 PM
ok syntax error is gone but the programm is not working :/

it starts and goes directly to the start screen but why ?

anyone ideas ?
Creator #10
Posted 05 April 2015 - 09:50 PM
term.clear()

drive1 = "disk_0"-- Disk Drive 1
drive2 = "disk_1"-- Disk Drive 2
disklabel = "Securitycard" -- Disk Label Needed
Securitylp = "Level 1 File" -- Security Level File Needed on Keycard
currentDisk = ""





while true do

if (disk.isPresent(drive1) or disk.isPresent(drive2)) then-- check if keycard in drive 1 or drive 2
  currentDisk = disk.isPresent(drive1) and "disk_1" or "disk_2"
   current_disklabel = disk.getLabel(currentDisk)-- get disklabel from disk
   if (current_disklabel == disklabel) then-- if disklabel = Needed disk Label
	 local file = fs.open(currentDisk.."/file", "r")-- search for Security File
	 if file.readAll() == Securitylp then-- when security file exist then give redstone signal
		redstone.setOutput("bottom", true)
		disk.eject("disk") --put Keycard out
		sleep(10) --wait 10 seconds and set redstone signal 0
		redstone.setOutput("bottom", false)
	 else (print("false"))-- restart computer or repeat the loop
   else (print("false"))-- restart computer or repeat the loop
end
end	  

Here is the the a little more lua standard following code ;)/>
darcline #11
Posted 05 April 2015 - 11:29 PM
oh thanks for your work but i write it complete new :D/> but your work was not totally (have no word sorry)

but i have a little problem i work with 2 monitors but the text is on 1 monitor only but i dont understand why :/

heres a code and 2 screens


term.clear()			   --terminal clearen
local mon1 = peripheral.wrap("monitor_3")
local mon2 = peripheral.wrap("monitor_2")
pstop = ("left")		   --programm stop
disk1 = ("drive_0")	    --Laufwerk 1
disk2 = ("drive_1")	    --Laufwerk 2
door = ("bottom")		  --Tuer Ausgang
code = ("Securitycard")    --KartenLabel
scode = ("/disk/Level_1_File")   --Sicherheitsstufe 1

while not redstone.getInput(pstop) do
	 if disk.isPresent(disk1) == true then
	    mon1.clear()
	    if disk.getLabel(disk1) == code then
		   if fs.exists(scode) == true then
			  disk.eject(disk1)
			  redstone.setOutput("bottom", true)
			  sleep(10)
			  redstone.setOutput("bottom", false)
			  shell.run("reboot")
		   else
			    mon1.write("Nicht Authorisiert")
			    sleep(5)
			    shell.run("reboot")
		   end
	    else    mon1.write("Fehlerhafte Sicherheitskarte")
			    sleep(5)
			    shell.run("reboot")
	    end
	 else
		  mon1.write("Keycard Einstecken")
	 end
	 if disk.isPresent(disk2) == true then
		    mon2.clear()
		    if disk.getLabel(disk2) == code then
		    print(file_exist2)
			   if fs.exists(scode) == true then
				  disk.eject(disk2)
				  redstone.setOutput("bottom", true)
				  sleep(10)
				  redstone.setOutput("bottom", false)
				  shell.run("reboot")
			   else
				    mon2.write("Nicht Authorisiert")
				    sleep(5)
				    shell.run("reboot")
			   end	  
			 else
				   mon2.write("Fehlerhafte Sicherheitskarte")
				    sleep(5)
				    shell.run("reboot")
			 end
		  else
			   mon2.write("Keycard Einstecken")
		  end
	  sleep(0.5)
end			  

sorry i cant upload the screens have problem with vdsl
Bomb Bloke #12
Posted 05 April 2015 - 11:37 PM
Looks to be because you're rebooting the computer all the time - well before you get to the second half of your script, where you check what's in the second disk drive.
darcline #13
Posted 06 April 2015 - 12:35 AM
Look again ;)/>

Its an or function the First drive or the second drive Not the drives at Same time
But the text keycard einstecken(insert keycard) should on 2 Monitors at Same time in didnt clear the monitor
Bomb Bloke #14
Posted 06 April 2015 - 12:56 AM
while no redstone signal do
	if there's a disk in the first drive then
		if it's labeled as a keycard then
			if the first mounted disk has a "Level_1_File" on it then
				reboot!
			else
				reboot!
			end
		else
			reboot!
		end
	else
		Don't reboot!
	end
	
	-- Program can only reach this point if the computer hasn't rebooted already!
	
	if there's a disk in the second drive then
		mon2.clear()
		if it's labeled as a keycard then
			print(file_exist2)
			if the first mounted disk (again) has a "Level_1_File" on it then
				reboot!
			else
				reboot!
			end    
		else
			reboot!
		end
	else
		Don't reboot!
	end
end
darcline #15
Posted 06 April 2015 - 01:21 AM
Jep if a Disk in the First drive if Not it ask if a Disk in the second drive, if Not wait 0,5 seconds and ask again
The last Reboot you mean is for the card label


while no redstone signal do
	    if there's a disk in the first drive then
			    if it's labeled as a keycard then
					    if the first mounted disk has a "Level_1_File" on it then
							    reboot!
					    else
							    reboot!
					    end
			    else
					    reboot!
			    end
	    else
			    Don't reboot!
	    end
	   
	    -- Program can only reach this point if the computer hasn't rebooted already!
	   
	    if there's a disk in the second drive then
			    mon2.clear()
			    if it's labeled as a keycard then
					    print(file_exist2)
					    if the first mounted disk (again) has a "Level_1_File" on it then
							    reboot! Reboot Yep
					    else
							    reboot! Reboot YEP
					    end   
			    else
					    reboot! Reboot Yep
			    end
	    else
			    Don't reboot!  Here is no Reboot
	    end
end
Edited on 06 April 2015 - 01:23 PM