It's been the elephant in the room for a lot of ComputerCraft programmers that many people on the forums and many more who use the mod both separately and in mod packs are not programmers themselves- for many of them, the computers in CC were the first exposure any have had to programming in their lives before, and after seeing and watching all the amazing things that have been produced over the year, it can be a bit bewildering to know where to start making your own creations.
So if you've never made a program before in your life, if you don't really understand what programming is or how it makes computers work, this is a not-so-gentle introduction to our world, and a guide on how to get yourself into the right mind space to start making amazing creations of your own, as well as avoiding the common pitfalls that will not only discourage you but earn the ire of everyone else on the forums!
Note: This tutorial is not going to teach you how to program, but about the mindset and attitude you should bring to getting started.
I've downloaded the mod, it looks awesome! So… where's the desktop?
A lot of people just starting out with ComputerCraft are initially bewildered when they realize they don't know how CraftOS itself actually works, and can't get their computers to do anything at all just yet. If you're feeling discouraged at this very first step, don't feel bad because you're not in the minority.
CraftOS may look a bit complex but it's actually a very simple system. Your very first step should be type the following into your computer, followed by the <enter> key:
help
Who knew it was that easy? In addition to the in-game help, the wiki is full of information about how to navigate and operate the computers in CC, as well as some good tutorials on the forums here. You can track them down without too much effort. This is true of everything you will encounter from this point on: from using peripherals, to making early programs, networking with other computers- if you have a question about how to use your computers or how to program them, you'll probably be able to find an answer in the in-game help, the CC Wiki, www.lua.org or the Ask A Pro section of the forums if you dig deep enough. This should always be your first stop when there's something you don't understand.How do I make my computer do this?
This is a category of question that I've seen and received countless times by email and on the forum:
Can I make my turtle dig a hole?
Can I make my computer display some information for me?
Can I make my computer play a game?
Unfortunately asking this sort of question means you're probably not thinking about programming in the right way. To 'make my computer do this' implies thinking about the end product with no consideration to the process, which is actually the part of the problem you need to figure out. The question you want to be asking instead is what can my computer do? Once you have an idea for the capabilities of lua and the tasks CC can perform, you can start piecing together a solution for your problem.
This is the key to programming- finding a problem, dividing down that problem into smaller problems and solving each of them separately. Once you've got a little bit working, start on the next bit and build your solutions like that. No competent programmer sits down and says 'right I'm going to make a big program', then writes it in one continuous stream of consciousness any more than an engineer builds a machine by pouring liquid metal into one massive cast. Build the individual components first, test them, stick them together, test them again.
There are of course other approaches and some people may disagree, but if you're new, this is probably the best way to go.
I have an awesome idea for CC! How do I do it?
Over-ambitious ideas and poorly planned projects are disappointingly rife in the forums. Having an idea that's either too big, or especially would require skills you don't presently have is one that's probably doomed to failure. When making your first programs for CC, be sure to limit yourself to an idea you think you can manage and isn't clearly unfeasible. If you've seen turtles taking things from chests and thought 'Right! Lets make a full-feature operating system linked with a back-end database that manages a robotic stock-taking warehouse!', then it might be worth scaling back to something more manageable.
You don't have to give up on your grand design, and there's no reason you can't come back and try later after you've had a bit more practice with programming, but trying to climb the tallest mountain in the range having just learnt what a mountain is, is not a good idea. Start small, maybe take a small component of your idea and turn that into a program first. After all, Rome wasn't built in a day.
One last thing, if you do have a grand idea but don't know how to make it, don't ask questions like 'how do I build it' on the forums or in PMs, and especially don't ask people to build it for you. Experienced programmers will respond… negatively to unjustified demands on their time. Everyone is happy to help you with technical questions. Some people are happy to help you with debugging and testing. No one is happy with doing your work for you.
There's so much to know and everyone on here seems to know what they're doing- I have so many questions!
This is perhaps more a matter of etiquette and self-value, but never ask a question that
- You haven't already tried to answer yourself, or
- You wouldn't understand the answer to
Beginners will often fall into this trap because they want to solve their problem, rather than understand the solution, and again this is putting yourself in the wrong mindspace. Being given a solution, or one you don't understand is a missed opportunity to learn more about how to program and solve problems for yourself. Every time you solve a problem for yourself, you've become better at solving that kind of problem, so even if it seems really difficult, you should make an effort to at least try. Once you've really made an effort and have some code (even if it's broken), then now is a good time to ask for help, but make sure you know what you're asking and get an explanation rather than just a solution.
And of course, remember to be polite and clear, and not to be disrespectful to those trying to help you. Learning how to ask questions may seem like a strange skill but it's an important one. As a side note if you're asking questions on the IRC and you haven't used public IRC channels before, there's a long list of guidelines for etiquette and respect you should be aware of before you try, so hit up Google to learn more about it.
Wow this is hard! Can I haz the magical elixir you've all drunk to make you masters at programming?
There's this really weird misconception that all skilled CC programmers found some hidden information cache or ultra tutorial that converted them into programming gods overnight. Okay that's a bit of an over-dramatization, but certainly people will ask 'how did you get this good', I think expecting the answer to be 'I read this book', or 'I watched these tutorials'.
Bottom line there is no magic elixir. Programming is hard. It's very hard. It has its origins in applied mathematics and is a very challenging and demanding discipline. Most of the people here who are skilled programmers have been learning for years, some since their age was a single digits and others in college or university. What brings us all together is we've all spent a lot of time and worked hard to become good at it. Now, there's nothing to say you can't become just as good, in fact it's one discipline that most people can eventually learn with time and practice; just don't expect it to as easy as a link to a webpage. This expectation, and it's inevitable shattering, has discouraged many people when it shouldn't have.
Because challenging a past time as it is, it's not only surmountable, it can be extremely rewarding. Don't expect it all at once but if you're patient and diligent, you can find yourself achieving some really amazing things :)/>
I've only just started here and there's already so much on the forums, I have no idea how or even if I should make a contribution…
I'm not sure how many people have this problem (as obviously no one reports it) but I know I did when I first arrived here. Many of the people on the programmers have spent quite a lot of time with ComputerCraft and some have been programming for years, know more languages than you've had birthdays and have a huge portfolio of awesome work. How can my little door lock program hope to compete? Why am I here at all, if it's all been done?
The first thing you should know is you should be programming for yourself, not for other people. If your motives aren't about bettering yourself and making something you're proud of, you're here for the wrong reasons. Programming is a very personal past-time and the joy and satisfaction comes mainly from successfully solving those problems yourself and making something you're happy with. Community feedback is just icing on the cake. Don't undervalue your achivements either- just because someone has already produced something as good or better than you have, it doesn't make what you've made any less valuable or important, because most of that value was about the journey to building it, not the end product.
That said, if you've produce something you feel is somewhat novel, you should still post it in the programs, because even if another, better solution exists, there's no reason why it might have a slightly different focus or method of operation that sets it apart, possibly making it better suited to other tasks or purposes. Even your implementation might be noteworthy in some way, and useful for other members of the community. Now this does not mean that every little script you've made up should be put up in the hopes someone will find it useful, but if you've put together something that solves a common problem you feel could be useful to others, and its fairly novel (that is you can't see more than, say, 1 or 2 programs on the same topic in the forums), then it might be worth putting up and getting some feedback. Use your judgement on this.
Do you feel better, or worse? Both are valid responses, but either way I hope this helps you answer some broader questions you might have had but never asked yourself.
-NF