Help! Easy for anyone
#1
Posted 02 February 2014 - 10:33 PM
It should be controlled by buttons on the screen above... (7 long * 3 high)
The sides are for nuke control, the bottom is for emergancy door close
#2
Posted 02 February 2014 - 10:58 PM
#3
Posted 02 February 2014 - 11:27 PM
This is Ask a Pro, where we answer questions from people who are writing programs, not for where we take program requests. There are dozens of examples of what you are trying to do. You will be much better off learning to code it yourself.
Edited by surferpup, 02 February 2014 - 11:29 PM.
#4
Posted 03 February 2014 - 12:12 AM
#5
Posted 03 February 2014 - 01:28 AM
- Establish connections to your monitors using monitor=peripheral.wrap("whateverSide")
- Draw your buttons using monitor.setCursorPosition(x,y) and monitor.write (check out the term API)
- turn your redstone.setOutput(side) to on/off for each side you are using according to your needs (if you need bundled cables, there are tutorials on this as well)
- start your while loop to check for monitor touch events (os.pullEvent("monitor_touch)
- If the button was pressed, do what you need to do.
- continue your while loop.
It is very kind of awsmazinggenius to offer to write code to start you out, but you really can do this yourself.
Edited by surferpup, 03 February 2014 - 01:29 AM.
#6
Posted 03 February 2014 - 03:47 AM
You all can on take explaining it and improving upon it. I realized after I wrote it that it wasn't for launch control, but for door open/close control. No matter. Just modify it as necessary.
Edited by surferpup, 03 February 2014 - 04:19 AM.
#7
Posted 03 February 2014 - 05:11 AM

Edit:
- Updated some variable names.
- Changed event variable to a local variable due to ingie's whining (he was correct).
- Posted Screenshot of my test setup.
- Corrected typos
- Used math.floor function to effectively center label on button
Edited by surferpup, 03 February 2014 - 12:49 PM.
#8
Posted 03 February 2014 - 09:28 AM
EDIT: Damn ninja
Edited by awsmazinggenius, 03 February 2014 - 07:47 PM.
#9
Posted 03 February 2014 - 11:23 AM
Quote
challenge accepted
1. well done for taking up the banner/ putting your head above the parapet
which leads me onto:
2. ewwwww, you used global variables within in a function.....
[ but you're excused, due to 1.
#10
Posted 03 February 2014 - 12:22 PM
ingie, on 03 February 2014 - 11:23 AM, said:
Other than the event variable (my bad), there are no globals that I saw. But I might have missed one. Go take a shower, you will feel much better.
Please feel free to expand/explain/improve. After all, this is supposed to be a learning lesson for our friend weareborg2913 (although for all I know he hasn't seen any of these posts).
Edited by surferpup, 03 February 2014 - 12:28 PM.
#11
Posted 03 February 2014 - 12:29 PM
there's several others tho... monitor/buttonheight/buttonwidth - but i'm purely being purist for "comedy" effect ... i did hint that my pedantry was irrelevant in the circumstances
#12
Posted 03 February 2014 - 12:32 PM
awsmazinggenius, on 03 February 2014 - 09:28 AM, said:
You are welcome. Care to use it as the basis for a tutorial? This question seems to come up a lot. I tried to incorporate a few good practices in making it (use of tables for buttons, self-documenting code, event loop with both monitor touch and key events tested, local variables -- thanks ingie -- use of functions, organized code, checking redstone states, allow for both toggle and pulse). All elements of a good door control with touch button tutorial are here.
#13
Posted 03 February 2014 - 12:37 PM
ingie, on 03 February 2014 - 12:29 PM, said:
there's several others tho... monitor/buttonheight/buttonwidth - but i'm purely being purist for "comedy" effect ... i did hint that my pedantry was irrelevant in the circumstances
I took you at your tone -- that's why I said you were whining in my correction
For the record, the table buttons is local as are all the keys defined thereunder. Also, the variables monitor, buttonHeight and buttonWidth are declared local. You must have misread the code (shocking, right?). You are absolutely correct in pointing out that it is best practice to use local variables unless a global is absolutely essential. The only global I found was event, and I changed it. Good catch.
#14
Posted 03 February 2014 - 12:45 PM
surferpup, on 03 February 2014 - 12:32 PM, said:
i'd agree - it's basically what is called a "design pattern" isn't it... or several nice design patterns in one bit of code...
i was looking at some of the tutorials last night and thought how although there's a lot of excellent stuff on how to solve problems and how to use libraries and devices, there's nothing specific on patterns...
the reason i think about this is that i see CC as being as much an educational tool for the "Why Johnny Can't Code" argument, as anything else. So outlining principles of general coding style and pattern is as important as "how to do x" type tutorials. This way when today's teenage CC scripters go out to work, if they choose computing, then they have good discipline in how to recognise the same thing when it crops up again, by its pattern rather than its specific need.
if you get me
surferpup, on 03 February 2014 - 12:37 PM, said:
good good, i just wanted to make sure
surferpup, on 03 February 2014 - 12:37 PM, said:
my bad in my definition, by global, i mean variables scoped outside the function... i.e. not local to the function - which is bad-ish practice for later abstraction. I always pass such variables in as params even if they are local to the main program, as that way it's simpler to extract the functions to a separate API later if needed, without any changes to the method.
Edited by ingie, 03 February 2014 - 12:46 PM.
#15
Posted 03 February 2014 - 12:45 PM
ingie, on 03 February 2014 - 12:42 PM, said:
I get you. I actually wrote it because I have seen so many of these "Can you help me write a quick touch screen button program?" questions. So, instead of just cranking out a hack, I wanted to show that it is a relatively straightforward program that can be extended if you use good coding practices. Again -- basis for a good tutorial...
#16
Posted 03 February 2014 - 01:05 PM
surferpup, on 03 February 2014 - 12:45 PM, said:
aye, totally - i saw your button table and thought: nicely done. i have a similar table for my door proximity opening system - where additionally one of the values of a "door" item is the function by which the trigger is activated - it's things like this that make me love lua for its first-class functional style ability [ i link there not to patronise, obviously, but for others learning more about deeper principles of coding ]
p.s. sorry, i'd edited my previous post whilst you were typing that to explain what i meant by global variables - i don't like editing after a subsequent post as it can change context... but just so you know
#17
Posted 03 February 2014 - 01:16 PM
ingie, on 03 February 2014 - 12:45 PM, said:
There is a fine line between Object-Oriented (OOP) principles and functional programming. Both are possible in Lua, and yes, generally speaking abstraction is good. This code is primarily functional. In the code, I have essentially only two true "abstract" functions -- drawButton and allRedstoneOff (which doesn't get called in this program). Other than that, the rest rely at the very least on the buttons table, which I do not pass in. I felt going further on abstraction would make the code less readable for the purposes of a tutorial-like code. As such, they are more like driver-functions.
ingie, on 03 February 2014 - 01:05 PM, said:
Nice link to the wikipedia article on first-class functions. Did you miss a link to your code demonstrating this?
As for the rest - we're on the same page. No worries
#18
Posted 03 February 2014 - 01:21 PM
surferpup, on 03 February 2014 - 01:16 PM, said:
no, but see my PM
#19
Posted 03 February 2014 - 07:49 PM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











