Jump to content




1 terminal multiple disks


14 replies to this topic

#1 --Kaos--

  • Members
  • 21 posts

Posted 28 February 2018 - 03:08 PM

Hi alll

so i have tried to figurie this out myself and look online for about a week before finally giving in and asking for help.

what i am trying to do is the following

I have 1 terminal computer and 1 disk drive. The disk drive is on the top of the computer
back , front left and right have redstone connected to them

What i want to do is when i insert a disk named "level2" then it activates for example the left side redstone for a time and then turn off , however, if i put in a disk named "basement" then the right redstone is activated

the labels of the names are redundant tbh as i was looking for the computer to read the disk with the following

ie.

disk labeled BASEMENT has data written of
key = "basement"

disk labeled "level2" has data written of
key = "level2"


So instead of having loads of disks i can have 4 disks to 1 computer and 1 drive. I want them to be used as access keys to open up different places per floor so having loads of terminals is something that wouldnt work

can someone pleaaasee help me as this is driving me nuts

thanks

Kaos

Edited by --Kaos--, 28 February 2018 - 03:14 PM.


#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 28 February 2018 - 03:55 PM

Have the computer listen for disk events. When it receives one, check the label, then set the appropriate output.

If you want to read the data on the disk, you'll need to open a file in text read mode ("r").

Edited by KingofGamesYami, 28 February 2018 - 03:57 PM.


#3 --Kaos--

  • Members
  • 21 posts

Posted 28 February 2018 - 04:43 PM

wow thats great thank you

i understand the idea of that but not sure how to put this into context.

i found someone elses code online who wrote
os.pullEvent = os.pullEventRaw
while true do
		if disk.isPresent("top") then
				if fs.exists("disk/.security/key") then
						shell.run("disk/.security/key")
						if key == "lemmein" then
								disk.eject("top")
								rs.setOutput("left", true)
								sleep(3)
								rs.setOutput("left", false)
						else
								disk.eject("top")
						end
				else
						disk.eject("top")
				end
		end
		sleep(0.1)
end
but this only works for one floppy disk

this is actually perfect if this worked for say 4 different floppy disks

Edited by --Kaos--, 28 February 2018 - 04:46 PM.


#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 28 February 2018 - 05:24 PM

local tKeys = {
	["basement"] = "right",
	["level2"] = "left",
	--# add additional entries here to pair more sides and phrases
}
while true do
	local event, side = os.pullEvent( "disk" )
	--#note: instead of checking 10 times a second,
	--#this only checks when a disk was inserted
	if disk.hasData( side ) and fs.exists( "/disk/.security/key", "r" ) then
		--#I check if the disk has data first, because technically
		--#it's possible to insert music disks which don't have a file system.
		local file = fs.open( "/disk/.security/key" )
		local key = file.readAll()
		file.close()
		--#running a program on a disk is a major security flaw of the progrm you posted
		--#that program could do anything, such as deleting all your files, or opening all the doors
		--#instead, here I read the file, the contents of which should simply be basement or level2
		if tKeys[ key ] then --#modify this to be "basement" or whatever you want
			--#eject the disk
			disk.eject( side )
			rs.setOutput(tKeys[key], true)
			sleep(3)
			rs.setOutput(tKeys[key], false)
		else --#add additional elseifs before the else to add different sides.
			disk.eject( side )
		end
	end
end

Edited by KingofGamesYami, 28 February 2018 - 06:13 PM.


#5 --Kaos--

  • Members
  • 21 posts

Posted 28 February 2018 - 05:25 PM

omg you are amazing!!!

i cannot thank you enough!!!!

what a legend :)

Edited by --Kaos--, 28 February 2018 - 05:25 PM.


#6 --Kaos--

  • Members
  • 21 posts

Posted 28 February 2018 - 05:48 PM

Hi again

for some reason the programme seems to stop

i set the programe as startup
i get "startup:9: expected String, string

i assume the part its point to is line
if tKeys[ key ] then --#modify this to be "basement" or whatever you want"

ive put it in as
[basement]
["basement"]
"basement"
but stil not playing

this stuff is hard man hahahaha

Edited by --Kaos--, 28 February 2018 - 06:19 PM.


#7 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 28 February 2018 - 06:15 PM

I think I've fixed it now. Writing code without actually testing it is difficult and I've been doing too much Java / C++ lately.

#8 --Kaos--

  • Members
  • 21 posts

Posted 28 February 2018 - 06:20 PM

you doing this without testing it is better than me with the entire internet and testing it!

your skills are superb

#9 --Kaos--

  • Members
  • 21 posts

Posted 28 February 2018 - 06:34 PM

am i correct in saying this based on your expert knowledge

local tKeys = {
		["basement"] = "back",
		["level2"] = "left",
}
while true do
		local event, side = os.pullEvent("disk")
		if disk.hasData("top") and fs.exists( "/disk/.security/key", "r") then
				local file = fs.open( "/disk/.security/key" )
				local key = file.readAll()
				file.close()
				if tKeys["basement"] then
						disk.eject("top")
						rs.setOutput(tKeys[key], true)
						sleep(3)
						rs.setOutput(tKeys[key], false)
				elseif
		tKeys["level2"] then
						disk.eject("top")
						rs.setOutput(tKeys[key], true)
						sleep(3)
						rs.setOutput(tKeys[key], false)
	else
						disk.eject("top")
				end
		end
end

currently fails
startup:7: Expected String

Edited by --Kaos--, 28 February 2018 - 06:44 PM.


#10 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 28 February 2018 - 06:46 PM

You've got the "r" slightly mixed up between lines 6 and 7. It should actually be:

if disk.hasData("top") and fs.exists( "/disk/.security/key" ) then
  local file = fs.open( "/disk/.security/key", "r" )

Edited by SquidDev, 28 February 2018 - 06:46 PM.


#11 --Kaos--

  • Members
  • 21 posts

Posted 28 February 2018 - 06:55 PM

im so glad knowledgable people like yourself exist as this is more complicated than i first thought ! haha

honestly, its appreciated like so much!

Startup:13: Expected string Boolean

:S

figured it out

the Boolean was because the part
rs.setOutput(tKeys[key], true)

should be
rs.setOutput(tKeys["basement"], true)

testing more as we speak but so grateful guys

#12 --Kaos--

  • Members
  • 21 posts

Posted 28 February 2018 - 07:16 PM

so update

basement works fine

the code works as it should. the disk ejects, the redstone at the back lights up and then turns off

however, if i do the exact same thing with a floppy disk with level2 it does nothing ,no ejection or redstone

its like its being ignored :s

#13 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 28 February 2018 - 10:09 PM

I'm terribly sorry I've been messing this up so much, thought this would be super easy to write. Had a bunch of classes to take but I'm back now :)/>
Spoiler
Don't actually modify the part that was marked as "modify this" with a comment earlier -- that was accedentially left in there from an earlier design. The only part you should need to change is the table at the top.

Edited by KingofGamesYami, 28 February 2018 - 10:11 PM.


#14 --Kaos--

  • Members
  • 21 posts

Posted 28 February 2018 - 10:19 PM

View PostKingofGamesYami, on 28 February 2018 - 10:09 PM, said:

I'm terribly sorry I've been messing this up so much, thought this would be super easy to write. Had a bunch of classes to take but I'm back now :)/>
Spoiler
Don't actually modify the part that was marked as "modify this" with a comment earlier -- that was accedentially left in there from an earlier design. The only part you should need to change is the table at the top.

hehe its okay.

your time on this is very kind of you

i really appreciate it honestly, forever in your debt :)

#15 --Kaos--

  • Members
  • 21 posts

Posted 28 February 2018 - 10:32 PM

So the disks eject as per the terms of basement and level2 but the redstone doesnt light up from the direction

im sorry i am not much use of this, im learning stacks of information from what you are giving so im learning as we go along
!

i fixed it!

it was the path in the end that was causing the major issues, i change the path just to /disk/disk/ in the code and now reads like a dream!!!!!

thanks so much!!!!

Edited by --Kaos--, 28 February 2018 - 10:44 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users