Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Programming attempt....again.  (Read 914 times)

Gilferedir

  • Bay Watcher
    • View Profile
Programming attempt....again.
« on: July 03, 2010, 02:42:39 pm »

Recently finding and playing Dwarf Fortress the last few weeks has inspired me to try and learn how to program,  probably my 4th or 5th attempt.  All other attempts have failed fairly quick, and perhaps my brain just doesn't work that way.  Hopefully this time I will try and stick too it and get a little further than just "Hello World" and basic math problems.  :D  Anyone else have multiple failed attempts at learning to program, but eventually had it all click?
Logged

Sir Pseudonymous

  • Bay Watcher
    • View Profile
Re: Programming attempt....again.
« Reply #1 on: July 03, 2010, 02:59:20 pm »

Kind of. I learned a little TI Basic on my old graphing calculator, then tried C, gave up, tried C again, gave up, found python, learned python, finally got it, learned C/C++ and a little java (which is useless, and horrible, and should go die in a fire).

The difficulty comes more from learning how to organize things into something that can be programmed than anything specific with the syntax and api's a given languages has, so something like Python is ideal for starting from (it's practically pseudocode, so it's much easier to pick up the syntax and start learning how to make it all come together than with something like C++ that's quite cryptic and incomprehensible if you don't already know what you're doing). Once you have the basic syntax down, just try to come up with simple tasks you could try to make a program to do, and keep the api reference handy. The most important thing to do is just keep at it, and practice actually programming with it.


inb4 "OH LOOK IT'S THIS THREAD AGAIN WHY DON'T YOU ALL JUST SHUT UP AND GO DIE OR SOMETHING INSTEAD OF TALKING ABOUT ANYTHING BECAUSE I'VE READ ALL THIS BEFORE WHARGLBARGLBARGL!!11!!"
Logged
I'm all for eating the heart of your enemies to gain their courage though.

Gilferedir

  • Bay Watcher
    • View Profile
Re: Programming attempt....again.
« Reply #2 on: July 03, 2010, 03:45:09 pm »

Yeah C++ is the one I always try learning, because I don't really have any direct use of any others so I figure it would be a good base to start with.  This is usually what most of my attempts feel like.

Mike and Bob speak <insert their native language here>,  Mike knows <language Bob wants to learn> very well and Bob wants him to teach him.

 (In their native language)
Bob says "Hey Mike, I was wondering if you could teach me <other language>?

Mike responds "Sure Bob, I could do that.  We can start with something simple"

Bob "Great!"

Mike "I'll teach you how to say your name, it goes like this.  (In other language) Hi, my name is Bob!.

Bob "That seems easy I"ll try.  (in other language) Hhi, mmy na me is Bob.

Mike "There you go.  See "hi" is a greeting, and "my" refers to yourself,  "name" is the word for name, and your name is just your name how you say it in our language.

Bob "Sweet!  I think I could get the hang of it.  What's next?"

Mike "Here is an unabridged Websters dictionary,  just memorize every word and definition in it first...then I"ll teach you how to put more sentences together"

Bob " :o "
Logged

Deathworks

  • Bay Watcher
  • There be no fortress without its feline rulers!
    • View Profile
Re: Programming attempt....again.
« Reply #3 on: July 03, 2010, 04:32:21 pm »

Hi!

Even though I have very little in finished products to show for it, I think I got a basic hang of programming, so I want to try to help you a little bit.

C++ is a good choice in my opinion, provided the libraries you use are properly installed (that is the reason why I prefer other languages/engines as some libraries drove me nuts). Stick to it, I suggest.

Programming itself is basically a loop of asking "How can I do this?". The first step in programming should be figuring out what program you want to create. You need to be precise about what you are looking for and need to put that vision in some kind of words or graphs, so you can easily continue investigating it.

So, you start with the question "What should happen?" and extend it to "What should happen if the user does this?" and also extend it to "What should happen next?".

One thing that can be useful in this context and for the next step is to consider the basic nature of computer programs:
Input => Processing => Output
Of course, modern computers and their programs mix these aspects a lot, but those three factors are what you are looking at nonetheless, and for every section of your project description, you want to check how each of these may be involved in that part.

For instance, let's say you want to create a classic 2D RPG. One of the elements you are looking at is moving around the place.
Quite obviously, the input by the player are direction keys and keys that trigger interaction.
Equally obviously, the output is the screen display and maybe sound effects.
The processing part, however, has several interesting subaspects:
1. The key pressed needs to be identified.
2. If it is a movement key, the program needs to check whether movement in that direction is possible (you don't want the player to walk through walls, for instance).
3. If it is a potentially possible movement, the program needs to check if trying to do so is supposed to trigger an event (for instance, a guard may move to block your way if you approach a door).
4. If it is a possible movement, the character needs to be actually moved to the new location.
5. If the character has been moved, the program has to check if that movement triggers any reaction (like the character moving onto a weak bridge that breaks under their weight, sending them to fall into a river)

This is just a simple, first list of thoughts, and it is probably not complete. The explanations in brackets are actually what you are likely to start out with (as in "Mmmhhh, if I have movement, I don't want the character to move through walls, so I need to check that.")

With this overview in hand, you can then start the programming process by asking repeatedly "How does the program do that?". Mind you, you are still on an abstract level, not thinking about code or anything, but rather about the logic behind it.

This actually does bring you to a technical aspect, though, and that is "data structure". For many tasks, figuring out how to store the necessary information best can save you a lot of pain and work once you develop the code. For instance, in the RPG example, you will need the information of what the map the character is currently on looks like. In a standard 2D RPG, such a map is made up of a combination of a limited number of rectangular tiles which fill a rectangular area. Since the number of tiles is limited, you can assume that you can give each tile (grass tile 1, grass tile 2, sand tile 1, table, ....) an ID number for later reference. Since you will also need to know where things are on the map (if nothing else, the character, at least), you need a way to identify a location on a map: a rectangular area of tiles - the obvious reference is clearing (x,y), a set of coordinates. So, for describing where something is located, we can use two numbers - how many tiles it is away from the left border and how many from the upper border of the map. This way, each possible location can be clearly identified.

With this in mind, you may want to think about what type of data structure is best suited for your purposes. While C++ allows you a lot of customization in that field, you should always start with the basic structures and see if they can comfortably fulfill your need.

If you look at most standard languages, you will find that there are ways to create x dimensional tables of basic data types. Given that you identify a specific location via two numbers (x and y) and that the data connected to it is a single number, a two-dimensional table seems to be the data structure of choice there.

While this is an easy and obvious example, there are many cases where you can actually make things easier by structuring the data in a certain way. Thus, it is always important to check what kind of information the computer needs to store and how you can optimize that information.

The programming process itself is then just a repetition of the question "How is this to be done?" until you get to a level so detailed that each bit of information corresponds to a single command in the programming language. For that purpose, you do not need to know all commands by heart, but instead look up the relevant sections in the manual each time you could imagine that there is already a command to do this. For instance, while it is unlikely that a general library will contain a command that allows you to put a part of a map based on tiles as described above, a graphic library is likely to include routines that will put a single static graphic onto the screen, thus allowing you to draw the graphic a single tile onto the screen. So, once you have reached the point where your logic states "draw the image defined as xx and yy by zzz at the location (x,y) of the screen" with all necessary information explained by the surrounding logic, you should check for the details of that routine.

Of course, since you are not aware of the quirks of the language yet, you may not be able to assess the availability of such commands, so instead of using the shortcut of guessing, you can also check at each step if a command already exists that does exactly what you are describing. If there is, you can use it, if not, you need to repeat the question "How can this be done?" on the logic level once more.

I think I have covered the bare basics there (I am a bit tired right now, so I may have missed something).

Deathworks
Logged

Blacken

  • Bay Watcher
  • Orange Polar Bear
    • View Profile
Re: Programming attempt....again.
« Reply #4 on: July 03, 2010, 09:35:06 pm »

C++ is generally a shit starting tool due to annoying-as-hell language inconsistencies and the more-difficult-than-it-ever-needed-to-be memory management (for newbies, anyway). If you are significantly determined you can do it, but it is harder than it needs to be to start with C++.

Without exception, I recommend Python as a starting language due to its simplicity and consistency. It's incredibly easy to start with and incredibly easy to pick up. The best book on learning to program and learning to think about programming that I have ever found can be found here. We have an IRC channel on the same IRC network as #bay12games - just /join #bay12prog if you've got questions and I, and a number of others, would be happy to help.
Logged
"There's vermin fish, which fisherdwarves catch, and animal fish, which catch fisherdwarves." - Flame11235

Deathworks

  • Bay Watcher
  • There be no fortress without its feline rulers!
    • View Profile
Re: Programming attempt....again.
« Reply #5 on: July 04, 2010, 01:50:00 am »

Hi!

Personally, I would consider Python to be actually less recommendable given its concept of name space which makes things unnecessary complicated. However, I don't think that the difference is great enough to really push a person this way or another way. As long as you stick to a structured language and not the classic BASIC, you should be fine (unstructured languages like the original BASIC tend to teach you approaches of coding that can be very problematic when you want to engage in proper programming).

Anyhow, regardless of which language you choose, ideally, I think the flow of your work should be as I described above.

Deathworks
Logged