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

"I'm new here- what do I do?" A tutorial to your first few steps

Started by nitrogenfingers, 10 June 2013 - 02:10 AM
nitrogenfingers #1
Posted 10 June 2013 - 04:10 AM
"I'm new here- what do I do???"

A tutorial to your first few steps into the world of Programming


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
superaxander #2
Posted 10 June 2013 - 05:26 AM
Really nice tutorial Will help the beginners good job!
billysback #3
Posted 10 June 2013 - 06:30 AM
I have an awesome idea for CC! How do I do it?
I think your comments one this are a bit negative;
in my experience (not so much in CC but in plugin programming for hMod, now CanaryMod, where I first learnt to properly program) one thing that made me make more and more plugins was the goal of making these incredible plugins that people were bringing out, seeing plugins like Stargates, WorldEdit and CraftBook come out whilst I was just starting was more of a goal than a put down. Whilst making my more amateur plugins I would start thinking up ideas for plugins which would be on par with these larger plugins. This goal to get that good and make a plugin that the community would see as "amazing" made me develop smaller plugins which honed my skills, I would do plugins which could make up smaller parts of these bigger plugin ideas I have, practicing all areas that these bigger ideas require me to have knowledge in.

Then and even now a simple comment as "well done" or "this is really good", however basic a comment it completely makes my day. It makes me think that all the effort I put in not only to make what they were commenting on but also the effort I put in to get to the level I had to get to make what they were commenting on, all of that effort seems worthwhile.

Basically, to sum what I'm trying to say up, you shouldn't tell people not to aspire to make these outrageously big projects, you should tell them to set these projects as their goal and to work towards this goal slowly. I agree that jumping in to the deep end isn't a good idea, but they should aspire to get in to the deep end.

I know that when I joined these forums pretty much the only thing I ever wanted to do was make games for CC, I've always seen it a challenge that never seems to get old, making a game with such limited resources and graphics to work off of. If I'm honest the obvious inspiration, or at least target, was your games and videos that were around when I joined. Although I'm not on level with you I can clearly see that I have improved and I hope I can say that without sounding arrogant.

Other than that I pretty much agree with everything else you say, good job :)/>

EDIT:
There's so much to know and everyone on here seems to know what they're doing- I have so many questions!
another point in this is one is that in my experience (again with programming plugins) I found that the best way to learn to program was to help others who are at the same level. When I first joined the hMod forums I spent most of my time in the programming section attempting to answer people who were asking for help, more specifically new members who were asking for help. By helping them out we both gained, We would both learn from their mistakes and together we would solve the problem, often with the help of a more skilled member.

The "Ask a Pro" section of these forums is the ideal location for this, if you just spend some time on the forums reading through other peoples problems and maybe trying to help them you will (or at least I did) find that you quickly learn more and more techniques.

EDIT EDIT:
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…
also on this one, you said about just posting your door lock program. If I'm honest I wouldn't advise this, there is so much hate directed at uncreative-ness on these forums that all this will do is down you further, people will direct hate at your thread and you will feel disheartened. Instead I would say do these practices in private, if you have a friend or a server you can show off to then show off you progress to them, then once you've practiced a little in private try to come up with an idea seems relatively creative, or do a creative spin on a common idea, then release this. I understand that feedback is often required for motivation, especially when you're starting, but only when it's positive feedback. Get feedback on your first programs from people who don't know how to make programs, or at least friends, they will find it all the more impressive and it will give you the confidence boost to make a program you should feel proud to release to the forums, a program that hopefully people will be nice about, the great thing about these forums is that they are so active that you are bound to get feedback, whatever your program is and even better, the majority of these forums are reasonably nice people, even if they are a bit satirical at times :P/>

NOW I think I've said what I have to say…
sorry for the very long feedback post, I'm not always the best at writing down my opinion on something but hopefully I got my points through.
nitrogenfingers #4
Posted 10 June 2013 - 07:23 AM
I have an awesome idea for CC! How do I do it?
I think your comments one this are a bit negative;
[…]
…you shouldn't tell people not to aspire to make these outrageously big projects, you should tell them to set these projects as their goal and to work towards this goal slowly. I agree that jumping in to the deep end isn't a good idea, but they should aspire to get in to the deep end.

My comments were fairly negative but I stand by them. Until you reach a certain level of competence it's hard to know what even is possible, and what frankly isn't or simply isn't feasible. Without a bit of programming background, understanding the grade and challenge of the work is very difficult, and there's nothing worse than seeing a programmer or group or programmers deadset on making the internet but in minecraft having done little more than a hello world tutorial, put all their eggs in that basket and when they don't achieve it they're disheartened to try anything more.

A down-to-earth discouragement from making that mistake now I think is better than doing it after hours or even days of fruitless effort. Start small and work your way up, leave your big ideas for when you think you can readily achieve them. Or, as I advised, find a small component of that project and work on that.

also on this one, you said about just posting your door lock program. If I'm honest I wouldn't advise this, there is so much hate directed at uncreative-ness on these forums that all this will do is down you further, people will direct hate at your thread and you will feel disheartened. Instead I would say do these practices in private, if you have a friend or a server you can show off to then show off you progress to them, then once you've practiced a little in private try to come up with an idea seems relatively creative, or do a creative spin on a common idea, then release this.

This I'll agree with, and have tweaked my tutorial to clarify my position on the issue. A door lock wasn't a good example. This actually relates back to an experience I had when I first started out here and built an email client/server system- at the time of release one or two similar systems existed and I was terminally shy about posting the code in fear of it being considered overdone and pointless. In retrospect, that probably wasn't the case.
This is a more specialized case I think, but I can imagine there are others like me that have made something that is worth displaying but choose not to because they're concerned it isn't up to scratch. Of course that depends on how many people like me there are out there and that, by nature being an unreported demographic is hard to judge. More worryingly, that's not carte blanc to post any little thing you make in the hopes it seems unique or interesting- that's a terrible idea! But if you've built something that seems interesting or exciting and does seem novel, that is you can't see anything on the first or second page of the relevant forum of the same subject or type, it might be worth putting up whether or not you're confident it stands among the best programs up here.

Appreciate the feedback BillysBack :)/> I wanted this more to be about keeping encouraged and avoiding common traps in early programming rather than community etiquette but the two seem surprisingly intertwined. I have taken your thoughts into account and I think they flesh out another perspective to this tutorial nicely.
GravityScore #5
Posted 10 June 2013 - 09:07 AM
Really great tutorial nitro! I've never personally thought of the last question, but I can see how some people when starting would.

In regards to:
Wow this is hard! Can I haz the magical elixir you've all drunk to make you masters at programming!?
I think you might want to add that the only way to become better at programming (or anything in general) is to actually just sit down and program. It doesn't matter what it is, even if its a complete clone of something on the forums, but just something to improve your skills - so that when you do have that magical idea you really want to make, you'll hopefully be able to make it. :)/>
Engineer #6
Posted 10 June 2013 - 05:58 PM
even if its a complete clone of something on the forums, but just something to improve your skills
Im going to add to that:

You should only do that as a reference. If you are programming whatever you are programming, and you are wondering how that person with a program with that functionality you are looking for, you should use that little snippet. But the next step is: how does this snippet work? Look up certain function calls, look up API's. Look everything up and try to understand that. If you dont understand it, ask it the author of that code!

I learned programming by studying code, and asking here on those forums. Never, never just say: 'oh, that works for some reason.. Dunno why..' and use it. Always understand code you are using!
MrBeaumont #7
Posted 25 June 2013 - 10:45 PM
Hi all,

Just want to give thanks for ComputerCraft and Minecraft. For those that understand programming this is awesome. Unfortunately, i do not understand it at all. Give me a hammer and nails or a nut and bolt, i'll fix any mechanical thing and make any construction, but programming is no way no can do.
I searched the net for a strip mining turtle, and found one that was great but was missing return and unload into a chest, so I did try to mix two programs to get one that i would like, the turtle just looked at me and laughed, haha.
Could someone offer to help,
I would like a strip mine 1x2 (length to be set by user) on return place torches every 10 blocks. If inventory slots fill up return and dump into enderchest then continue, or carry an enderchest and continually purge into it. Id like it to return and not get hung up on mobs etc. If fuel runs out, id like it to return to be refuled.
It's kind of like the "excavate" program but it just goes 1 wide and 2 high from the block where i place it.

Please help

Thanks
MrBeaumont
nitrogenfingers #8
Posted 27 June 2013 - 12:55 AM
My friend has a kayak he calls the Mr. Beaumont :P/>

So I'm going to go ahead and recommend you read the topic you posted in, in entirety. It doesn't answer your question but it should tell you how to go about finding an answer to your question.
GopherAtl #9
Posted 28 June 2013 - 12:35 PM
Something I think should be added in here somewhere:

Programing is not a test, it's a process.

Don't be afraid of errors. Errors happen even to the most experienced programmers. If you're not sure if some function you wrote will work, don't run off to the forums to find an expert and ask; just run the function and see what happens. If it doesn't work, try to figure out why! Sprinkle it with print() calls that let you see whats happening. If you're using new features for the first time, test them in the lua interpreter first, where your feedback on what works and what doesn't is immediate.

As you get more experienced, you'll get better at writing code that works the first time, and better at finding bugs when it doesn't, but you will never get past the need to debug. Starting out, you will likely spend the majority of your time debugging, not writing new code! New programmers sometimes seem to bring in habits from math classes, trying to just write a solution, then stare at the solution hoping any errors will appear to them, and think of running the program as being equivalent to turning in the test once you're finished. This is wrong. When starting out, and especially in a language like lua where there's no compile-link-build delay every time you test, it's easier to run the program and let the errors reveal themselves.