if so, what commands would I have to use in the code to make it look for the floppy file?
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Is it possible for me to write a code that loops and listens for a disk input?
Started by Darky_Alan, 23 July 2012 - 07:52 PMPosted 23 July 2012 - 09: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?
Posted 23 July 2012 - 10: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)
presence = disk.isPresent(side)
end
print(The side detected present first is "..side..".") –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)
presence = disk.isPresent(side)
end
print(The side detected present first is "..side..".") –this is disk detection, not disk drive detection
Posted 25 July 2012 - 04:34 AM
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.
Posted 25 July 2012 - 05:58 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
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 = 0
Is the variable that will be increased to represent the 6 sides
while presence == false do
This states that if the presence = disk.isPresent(side[i])
is true or not. The disk is in or not
i = i + 1
Is the increase in the 'i' value or in other words changing the sides
if i == 7 then i = 1 end
States that if 'i' or the side count is equal to '7' (there are only 6 sides) then reset to '1' and check againPosted 25 July 2012 - 06: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
Posted 25 July 2012 - 06:12 PM
was about to post the same, this is the right solution.
Posted 25 July 2012 - 07:05 PM
So I want it to listen for a "ticket" to be entered, and then read the "destination" program on the disk, and then the "destination" program will restart the os, and take the disk away using a filter. Where would I insert that command to run the shell?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 beginningAre the sides of the computer that will be searched:local sides = {'top' , 'bottom' , 'left' ,'right' , 'front' , 'back'}
Is the variable that will be increased to represent the 6 sidesi = 0
This states that if thewhile presence == false do
is true or not. The disk is in or notpresence = disk.isPresent(side[i])
Is the increase in the 'i' value or in other words changing the sidesi = i + 1
States that if 'i' or the side count is equal to '7' (there are only 6 sides) then reset to '1' and check againif i == 7 then i = 1 end
Posted 25 July 2012 - 10: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?
Posted 25 July 2012 - 10:39 PM
how to you define a label for a disk within lua?
As per the the Disk API: setLabel(string side, string label).
Posted 25 July 2012 - 10: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.info/wiki/index.php?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.info/wiki/index.php?title=Disk_(API)
//EDIT: Exa has been a bit faster than me..
Posted 26 July 2012 - 12:25 AM
You guys are the best, THANKS!
*runs off to code, whooping for joy*
*runs off to code, whooping for joy*
Posted 26 July 2012 - 01:55 AM
The wiki is your friendPay 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?
Posted 26 July 2012 - 07: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.