2
Is it possible for me to write a code that loops and listens for a disk input?
Started by Darky_Alan, Jul 23 2012 08:52 PM
12 replies to this topic
#1
Posted 23 July 2012 - 08:52 PM
What I mean by this is, is it possible to have a program loop and wait for a specific cd to be entered, have it look for a program and run it, else have it print "Incorrect disk" ?
if so, what commands would I have to use in the code to make it look for the floppy file?
if so, what commands would I have to use in the code to make it look for the floppy file?
#2
Posted 23 July 2012 - 09:50 PM
local sides = {'top', 'bottom', 'left', 'right', 'front', 'back'}
i = 0
while presence == false do
i = i+1
if i == 7 then i = 1 end
if not disk.isPresent(side[i])
presence = disk.isPresent(side[i])
end
print(The side detected present first is "..side[i]..".") --this is disk detection, not disk drive detection
i = 0
while presence == false do
i = i+1
if i == 7 then i = 1 end
if not disk.isPresent(side[i])
presence = disk.isPresent(side[i])
end
print(The side detected present first is "..side[i]..".") --this is disk detection, not disk drive detection
#3
Posted 25 July 2012 - 03:34 AM
KingMachine, on 23 July 2012 - 09:50 PM, said:
local sides = {'top', 'bottom', 'left', 'right', 'front', 'back'} i = 0 while presence == false do i = i+1 if i == 7 then i = 1 end if not disk.isPresent(side[i]) presence = disk.isPresent(side[i]) end print(The side detected present first is "..side[i]..".") --this is disk detection, not disk drive detection
Could you elaborate on how some of these parts work? I'm trying to build a ticketing system for a train station, and this sounds like it would be exactly what I need. I just don't want to go slicing it up to suit my needs before knowing how it actually works.
#4
Posted 25 July 2012 - 04:58 PM
craniumkid22, on 25 July 2012 - 03:34 AM, said:
KingMachine, on 23 July 2012 - 09:50 PM, said:
local sides = {'top', 'bottom', 'left', 'right', 'front', 'back'} i = 0 while presence == false do i = i+1 if i == 7 then i = 1 end if not disk.isPresent(side[i]) presence = disk.isPresent(side[i]) end print(The side detected present first is "..side[i]..".") --this is disk detection, not disk drive detection
Could you elaborate on how some of these parts work? I'm trying to build a ticketing system for a train station, and this sounds like it would be exactly what I need. I just don't want to go slicing it up to suit my needs before knowing how it actually works.
Yes, as mentioned in the above code the beginning
local sides = {'top' , 'bottom' , 'left' ,'right' , 'front' , 'back'}Are the sides of the computer that will be searched:
i = 0Is the variable that will be increased to represent the 6 sides
while presence == false doThis states that if the
presence = disk.isPresent(side[i])is true or not. The disk is in or not
i = i + 1Is the increase in the 'i' value or in other words changing the sides
if i == 7 then i = 1 endStates that if 'i' or the side count is equal to '7' (there are only 6 sides) then reset to '1' and check again
#5
Posted 25 July 2012 - 05:08 PM
local event, side = os.pullEvent("disk") name = disk.getLabel(side) if name == "CD Name" then -- whatever you want if it is the correct CD else print("Wrong CD") disk.eject(side) -- Its really easy guys
#6
Posted 25 July 2012 - 05:12 PM
was about to post the same, this is the right solution.
#7
Posted 25 July 2012 - 06:05 PM
cube123, on 25 July 2012 - 04:58 PM, said:
craniumkid22, on 25 July 2012 - 03:34 AM, said:
KingMachine, on 23 July 2012 - 09:50 PM, said:
local sides = {'top', 'bottom', 'left', 'right', 'front', 'back'} i = 0 while presence == false do i = i+1 if i == 7 then i = 1 end if not disk.isPresent(side[i]) presence = disk.isPresent(side[i]) end print(The side detected present first is "..side[i]..".") --this is disk detection, not disk drive detection
Could you elaborate on how some of these parts work? I'm trying to build a ticketing system for a train station, and this sounds like it would be exactly what I need. I just don't want to go slicing it up to suit my needs before knowing how it actually works.
Yes, as mentioned in the above code the beginning
local sides = {'top' , 'bottom' , 'left' ,'right' , 'front' , 'back'}Are the sides of the computer that will be searched:
i = 0Is the variable that will be increased to represent the 6 sides
while presence == false doThis states that if the
presence = disk.isPresent(side[i])is true or not. The disk is in or not
i = i + 1Is the increase in the 'i' value or in other words changing the sides
if i == 7 then i = 1 endStates that if 'i' or the side count is equal to '7' (there are only 6 sides) then reset to '1' and check again
#8
Posted 25 July 2012 - 09:13 PM
Pay no attention to the previous derpiness, but on the subject of reading disk labels, how to you define a label for a disk within lua?
#10
Posted 25 July 2012 - 09:43 PM
disk.setLabel(side, label)
side: the side on which you can find the disk drive
label: the label of the disk you want to set
for example:
disk.setLabel("left", "Keycard")
Check this: http://computercraft...title=Disk_(API)
//EDIT: Exa has been a bit faster than me..
side: the side on which you can find the disk drive
label: the label of the disk you want to set
for example:
disk.setLabel("left", "Keycard")
Check this: http://computercraft...title=Disk_(API)
//EDIT: Exa has been a bit faster than me..
#11
Posted 25 July 2012 - 11:25 PM
You guys are the best, THANKS!
*runs off to code, whooping for joy*
*runs off to code, whooping for joy*
#13
Posted 26 July 2012 - 06:04 AM
You know, I don't know why, but I assumed he was asking how to detect if any disk drive had received a disk. I probably misread something.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users