This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Sora Firestorm's profile picture

Keypad Lock

Started by Sora Firestorm, 17 February 2013 - 05:51 PM
Sora Firestorm #1
Posted 17 February 2013 - 06:51 PM
Nothing too special, but I did spent a decent part of today writing this little program.
One of the things I'm proud of is the customization ability of the layout and colors.

Places that are specifically designed to allow customization :
1. The button locations. There is a table at the top which contains coordinates for each button,
including the display. Any valid screen location is fine for any button.
2. Colors of the buttons and text. Simple couple of variables at the top set to values from the colors table.
3. onSuccess and onFail functions for doing things depending on if the code is valid or not.
This allows the code to function for different tasks, like making this program necessary to unlock a terminal.
For me, I have this hooked up to a door, that opens on correct, and pistons that push up portal gun mod turrets up on incorrect.
These functions have been left blank in the pastebin.

Pictures of a 'default' layout
Spoiler


Pastebin link
http://pastebin.com/2cvdi85C

I hope the code is semi-readable, go ahead and suggest on how to make it better. :)/>

Enjoy,
~Sora
GravityScore #2
Posted 17 February 2013 - 07:10 PM
Nice program. I like the customisation too.

Couple of suggestions:
1. Could you restore the os.pullEvent once the answer is correct? That way when we enter the shell we are able to use control t again.
2. Move the onCorrect and onFailure functions to the top of the file so they're easy to find and edit when looking at this in game.
3. When checking if the computer is an advanced computer, also check the actual function term.isColor exists before calling it, otherwise on Tekkit your program will crash (it will give an attempt to call nil error as the term.isColor function doesn't exist). Like so: if term.isColor and term.isColor() then
4. In lua, you aren't required to end every statement with a semicolon like in most other languages (it still lets you though). It's a matter of personal preference, but just letting you know :P/>
theoriginalbit #3
Posted 17 February 2013 - 07:17 PM
Nice work :)/> screenshots would be nice :)/>

1. Could you restore the os.pullEvent once the answer is correct? That way when we enter the shell we are able to use control t again.
To expand on this, just incase you didn't know he means this

-- at the top
local oldPull = os.pullEvent
os.pullEvent = os.pullEventRaw

-- then what gravity means
os.pullEvent = oldPull

4. In lua, you aren't required to end every statement with a semicolon like in most other languages (it still lets you though). It's a matter of personal preference, but just letting you know :P/>
I don't actually mind it, keeps the habit going for other languages… :)/> im gunna be so stuffed when I go back to real languages :P/>
Sora Firestorm #4
Posted 17 February 2013 - 07:17 PM
1. Sorry about that. Part of the nonspecializing that I forgot to do.
Done
2. That actually sounds like a good idea, hopefully I will remember to do that.
Done
3. Oh… well, this program won't work without the Adv. Term functions anyways. I personally don't consider this important to fix.
Done
4. I know. :)/>
It comes from my Perl and C (ala end statements with semis) background, so I prefer to do it when it doesn't break syntax.
I write all of my Lua code this way. :D/>

EDIT : Fixed all of the bugs, got new pastebin and some screens up. Thank you for attention