7 posts
Posted 02 September 2012 - 10:48 AM
Hi guys,
I am in the process of programming a computerized Railway whereby a passenger (Only one can use the railway at a time) buys a floppy which contains a program and they put it into the floppy drive. The only things I am stuck on are;
- What code would I need to put on the computer itself to it reads any floppy entered and runs its program automatically? It needs to be in a loop so no-one has to come over and be at the computer to manage it. (I can program the code for the railway instructions, I just don't know what kind of code would need to be put on the computer for it to listen to floppys)
- Is there any caching that needs to be done, as the floppy needs to be ejected immediately after being popped in (The program will be running after it has popped back out) so the passengers can keep their program?
All the program on the floppy will be is a list of redstone output and sleep instructions which will precisely change the direction of tracks after a certain amount of time (I will calculate this beforehand) thereby sending the passengers' train where they wish to go.
Obviously the other option is to do it all in one big program on the computer and have the floppies contain a number depending on the route but if I need to add a route or alter one, I would have to take the program offline rendering the railway unusable for some time.
Any ideas?
66 posts
Posted 02 September 2012 - 11:27 AM
working on this now, do you want them to get the floppy back after they put it in?
236 posts
Location
Germany
Posted 02 September 2012 - 11:42 AM
do this:
while true do
local ev,side = os.pullEvent()
if ev == "disk" then
local path = disk.getMountPath(side)
path = path.."/program"
local file = fs.open(path,"r")
local raw = file:readAll()
file:close()
disk.eject(side)
local runme = loadstring(raw)
runme()
end
end
dunno if it works like this cant test atm ;(
686 posts
Posted 02 September 2012 - 03:17 PM
It would a better alternative to simply check for a certain file on the floppy and run a function containing the instructions to get where they are going, than to run a program on any floppy inserted.
7 posts
Posted 02 September 2012 - 08:12 PM
working on this now, do you want them to get the floppy back after they put it in?
as the floppy needs to be ejected immediately after being popped in (The program will be running after it has popped back out) so the passengers can keep their program?
Yes please, its just so that it doesn't end up with 50 odd disks in a pit at the stations :D/>/>
do this:
while true do
local ev,side = os.pullEvent()
if ev == "disk" then
local path = disk.getMountPath(side)
path = path.."/program"
local file = fs.open(path,"r")
local raw = file:readAll()
file:close()
disk.eject(side)
local runme = loadstring(raw)
runme()
end
end
dunno if it works like this cant test atm ;(
Thanks! I'll give it a go when I'm back in minecraft.
7 posts
Posted 03 September 2012 - 05:08 PM
do this:
while true do
local ev,side = os.pullEvent()
if ev == "disk" then
local path = disk.getMountPath(side)
path = path.."/program"
local file = fs.open(path,"r")
local raw = file:readAll()
file:close()
disk.eject(side)
local runme = loadstring(raw)
runme()
end
end
dunno if it works like this cant test atm ;(
Unfortunately this doesn't work:
"railway:9: bad argument: string expected, got nil"
Thank anyway though :D/>/>
236 posts
Location
Germany
Posted 03 September 2012 - 06:39 PM
do this:
while true do
local ev,side = os.pullEvent()
if ev == "disk" then
local path = disk.getMountPath(side)
path = path.."/program"
local file = fs.open(path,"r")
local raw = file:readAll()
file:close()
disk.eject(side)
local runme = loadstring(raw)
runme()
end
end
dunno if it works like this cant test atm ;(
Unfortunately this doesn't work:
"railway:9: bad argument: string expected, got nil"
Thank anyway though :D/>/>
weird it runs fine for me o.O 1 second lemme check that
this works on mc1.2.5 with v 1.41
while true do
local ev,side = os.pullEvent()
if ev == "disk" then
local path = disk.getMountPath(side)
path = path.."/program"
local file = fs.open(path,"r")
local raw = file:readAll()
file:close()
disk.eject(side)
local runme = loadstring(raw)
runme()
end
end
try using this as the disk program
print("bacon")
thats what i used for testing
7 posts
Posted 03 September 2012 - 07:26 PM
do this:
while true do
local ev,side = os.pullEvent()
if ev == "disk" then
local path = disk.getMountPath(side)
path = path.."/program"
local file = fs.open(path,"r")
local raw = file:readAll()
file:close()
disk.eject(side)
local runme = loadstring(raw)
runme()
end
end
dunno if it works like this cant test atm ;(
Unfortunately this doesn't work:
"railway:9: bad argument: string expected, got nil"
Thank anyway though :D/>/>
weird it runs fine for me o.O 1 second lemme check that
this works on mc1.2.5 with v 1.41
while true do
local ev,side = os.pullEvent()
if ev == "disk" then
local path = disk.getMountPath(side)
path = path.."/program"
local file = fs.open(path,"r")
local raw = file:readAll()
file:close()
disk.eject(side)
local runme = loadstring(raw)
runme()
end
end
try using this as the disk program
print("bacon")
thats what i used for testing
My Apologies, I missed the line:
local raw = file:readAll()
lol! Works really well. Thanks very much!
236 posts
Location
Germany
Posted 03 September 2012 - 07:54 PM
do this:
while true do
local ev,side = os.pullEvent()
if ev == "disk" then
local path = disk.getMountPath(side)
path = path.."/program"
local file = fs.open(path,"r")
local raw = file:readAll()
file:close()
disk.eject(side)
local runme = loadstring(raw)
runme()
end
end
dunno if it works like this cant test atm ;(
Unfortunately this doesn't work:
"railway:9: bad argument: string expected, got nil"
Thank anyway though :D/>/>
weird it runs fine for me o.O 1 second lemme check that
this works on mc1.2.5 with v 1.41
while true do
local ev,side = os.pullEvent()
if ev == "disk" then
local path = disk.getMountPath(side)
path = path.."/program"
local file = fs.open(path,"r")
local raw = file:readAll()
file:close()
disk.eject(side)
local runme = loadstring(raw)
runme()
end
end
try using this as the disk program
print("bacon")
thats what i used for testing
My Apologies, I missed the line:
local raw = file:readAll()
lol! Works really well. Thanks very much!
you're welcome