7 posts
Location
Minecraftia
Posted 11 July 2012 - 10:02 PM
My very noobish, very new-to-lua-programming programs :)/>/>
Room Key
=========
An incredibly simple LUA program which goes onto a computer next to a disk drive. It's under the 'startup' file, and I also added a "check" program. Basically the title of the floppy disk is the code. The program reads it if it's there, and opens the door if it's correct. -Simple-!
I made a video on it, which I'll try to figure out how to embed in this in a few minutes.
So, here's the code for it:
tArgs = ...
driveSide = tArgs[2]
doorSide = tArgs[1]
print("Enter Room Key.")
if (disk.isPresent(driveSide) ) then
label = disk.getLabel(driveSide)
if (label == diskName) then
redstone.setOutput(doorSide,true)
disk.eject(driveSide)
print("Welcome Home.")
sleep(3)
redstone.setOutput(doorSide,false)
print("Remember to shutdown.")
else
print("Invalid Room Key.")
disk.eject(driveSide)
sleep(4)
os.shutdown()
end
else
print("Room Key Not Detected.")
sleep(4)
os.shutdown()
end
Tis as easy as that! Thanks for reading.
On looping: Adding a simple sleep(4) then os.shutdown() feature works well enough for looping it, I'll tweak it some more though. Code update!
EDIT: Quick addition again, I changed it so when you enter the correct room key it doesn't automatically shutdown. This is for other uses you might want from it.
864 posts
Location
Sometime.
Posted 11 July 2012 - 10:46 PM
It only works for a door to the left and a diskdrive on the top.
You should set variables for the two and then have people change that.
7 posts
Location
Minecraftia
Posted 11 July 2012 - 10:49 PM
It only works for a door to the left and a diskdrive on the top.
You should set variables for the two and then have people change that.
Again with my noob-ishness, but what do you mean by set variables for them? I assume you mean that I should write "driveSide" as opposed to "top" and such? I'll do that :)/>/>
86 posts
Posted 12 July 2012 - 12:32 AM
define driveSide as an argument by doing tArgs = … at the start of the program, and driveSide = tArgs[2]. Also do doorSide = tArgs[1].
86 posts
Posted 12 July 2012 - 12:33 AM
( you use these variables in place of "top" and "left", so that they can be changed )
86 posts
Posted 12 July 2012 - 12:43 AM
Oh, and don't surround driveSide and doorSide with quotes, as they're variables.
86 posts
Posted 12 July 2012 - 12:46 AM
You also have to add
tArgs = ...
driveSide = tArgs[2]
doorSide = tArgs[1]
As I've not figured out where to put these settings, they're the arguments of the program, you specify them by doing
DoorLock left top
(quotes around arguments not required because they can't be variables)
445 posts
Posted 12 July 2012 - 09:10 AM
Should loop it.. looks like it would only work once atm?
7 posts
Location
Minecraftia
Posted 12 July 2012 - 01:21 PM
Should loop it.. looks like it would only work once atm?
Indeed, it only works once. I got around this the cheap way by adding a "check" program which starts from checking if a disk is in, but I'll work on the looping now =P
EDIT: Done (Simply, but done nonetheless. Most stuff here is done "simply")
1 posts
Posted 12 January 2013 - 03:55 PM
when i entered it in it said
bios:206: [string "startup"]:16: unexpected symbol
i checked line 16 and it was the same thing it said on the code. plz help
ps i entered in the exact code not a word different (well maybe a fue mistakes)
497 posts
Location
The Big Apple, NY
Posted 12 January 2013 - 04:37 PM
dude don't bump a 6 month old self labeled "noob" program
7508 posts
Location
Australia
Posted 12 January 2013 - 04:40 PM
i checked line 16 and it was the same thing it said on the code. plz help
You n00b'd it up bad… this on line 16 and 17
[/size][/size]
[size=6][size=4]
in the code is a mistake… its tags for the forum, not Lua code…