Jump to content




Is it possible for me to write a code that loops and listens for a disk input?


12 replies to this topic

#1 Darky_Alan

  • Members
  • 89 posts
  • LocationPuerto Rico

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?

#2 KingMachine

  • Members
  • 122 posts

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

#3 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 25 July 2012 - 03:34 AM

View PostKingMachine, 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 LNETeam

  • Members
  • 111 posts
  • LocationEclipse

Posted 25 July 2012 - 04:58 PM

View Postcraniumkid22, on 25 July 2012 - 03:34 AM, said:

View PostKingMachine, 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 = 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 again

#5 tfoote

  • New Members
  • 134 posts
  • LocationSalt Lake, UT

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 Xfel

    Peripheral Designer

  • Members
  • 515 posts

Posted 25 July 2012 - 05:12 PM

was about to post the same, this is the right solution.

#7 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 25 July 2012 - 06:05 PM

View Postcube123, on 25 July 2012 - 04:58 PM, said:

View Postcraniumkid22, on 25 July 2012 - 03:34 AM, said:

View PostKingMachine, 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 = 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 again
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?

#8 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

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?

#9 Exa

  • New Members
  • 1 posts

Posted 25 July 2012 - 09:39 PM

View Postcraniumkid22, on 25 July 2012 - 09:13 PM, said:

how to you define a label for a disk within lua?

As per the the Disk API: setLabel(string side, string label).

#10 Patistar

  • Members
  • 13 posts

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

#11 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 25 July 2012 - 11:25 PM

You guys are the best, THANKS!
*runs off to code, whooping for joy*

#12 tfoote

  • New Members
  • 134 posts
  • LocationSalt Lake, UT

Posted 26 July 2012 - 12:55 AM

View Postcraniumkid22, on 25 July 2012 - 09:13 PM, said:

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?
The wiki is your friend

#13 KingMachine

  • Members
  • 122 posts

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