Jump to content




New Disk API function


8 replies to this topic

#1 thecrimulo

  • Members
  • 87 posts
  • Locationhere

Posted 04 January 2017 - 02:01 PM

Hi there,
I request a new Disk API function that returns the device type inserted on a side, either "computer", "floppy" or "disc".

#2 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 04 January 2017 - 03:21 PM

Can kind of be implemented by the user by having a type file at the root of the disk/disk-like-device's filesystem which identifies the device type.

A device without this file will have to be identified by the user, although computers/turtles could be programmed to make their own on startup.

You might be able to do something fancy with the varying storage capacities of different devices.

Also, why would you need this? I can't see any need to know what's in the drive while it's in the drive. A turtle can identify it for you if you really need to.

Edited by Lupus590, 04 January 2017 - 03:24 PM.


#3 thecrimulo

  • Members
  • 87 posts
  • Locationhere

Posted 04 January 2017 - 05:03 PM

I am making a Virtual Filesystem adaptation with devices, partitions and such. There is a file that can specify it but not every device is going to have them. That's why I wanted it in a function (and Turtles don't help because in some servers it is not allowed)

#4 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 04 January 2017 - 05:55 PM

As Lupus590 suggested, you can probably use the different storage sizes to determine what storage medium you are examining. The downside is that I believe those values can be changed in the config, so they wouldn't be guaranteed to be the same on every server you play on.

#5 thecrimulo

  • Members
  • 87 posts
  • Locationhere

Posted 04 January 2017 - 07:05 PM

I've researched for the capacity of computers, pocket computers (1,000,000) and floppys (125,000), here is a function outline that differences them by size:

function disk.getDevice(side)
	if disk.hasData(side) then
		local sMountPath = disk.getMountPath(side)
		local nFreeSpace = fs.getFreeSpace(sMountPath)
		if nFreeSpace <= 125000 then return "floppy"
		elseif nFreeSpace > 125000 then return "computer"
		end return nFreeSpace
	else return nil end
end

Anything beyond 125,000 is considered computer because of that it is configurable and it might be less or more than 1,000,000.

However, it would be fine to have a function that just detects it, instead of the size trick, so its always exact.

#6 TheRockettek

  • Members
  • 547 posts
  • LocationRem is best girl

Posted 04 January 2017 - 08:25 PM

floppy space is configurable too ya know :P

#7 houseofkraft

  • Members
  • 170 posts
  • LocationUSA

Posted 04 January 2017 - 08:26 PM

All you need to do is check what type the peripheral side is. The code below might work

function disk.getDevice(side)
     if peripheral.getType(side) == "computer" then
       return "computer"
     elseif peripheral.getType(side) == "disk" then
       return "floppy"
     else
       return "unknown"
     end
end


#8 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 04 January 2017 - 08:32 PM

View Posthouseofkraft, on 04 January 2017 - 08:26 PM, said:

All you need to do is check what type the peripheral side is. The code below might work
the computer is in the disk drive so your code will always think it is a floppy even though the disk drive contains a computer

#9 thecrimulo

  • Members
  • 87 posts
  • Locationhere

Posted 04 January 2017 - 10:04 PM

View PostTheRockettek, on 04 January 2017 - 08:25 PM, said:

floppy space is configurable too ya know :P

One more reason to need the function





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users