Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Learning coding using Dwarf Fortress  (Read 4660 times)

sculleywr

  • Bay Watcher
    • View Profile
Learning coding using Dwarf Fortress
« on: April 28, 2016, 04:55:36 am »

I decided to start learning coding, and since my lessons on Codecademy wanted me to come up with content to go inside the HTML tags, I decided to use my Dwarf Fortress fortress as a source for the lesson on building a social media profile. Here's the result of my longest code yet, with 104 lines of code with very simple hierarchy, as I am a beginner at this stuff. It took a bit of bodging because my results in the first part of the course caused several of the lists to end up in the wrong level until I went through every "li" tag to find the mistakes.

Code: [Select]
<!DOCTYPE html>
<html>
<head>
<title>Udib Letmosbetan</title>
</head>
<body style="font-family:monospace; color:#006400; background-color:#FF5BFB">
    <img src="http://www.conceptart.org/forums/attachment.php?s=3947d7a3a50c1904c87a7d3081afeeee&attachmentid=1653911&stc=1&d=1354882440">
    <p><em>He is eighty-five years old, born on the 19th of Opal in the year 165. He is incredibly skinny. His sideburns are clean-shaven. His very long moustache is neatly combed. His very long beard is arranged in double braids. His medium-length hair is neatly combed. He has a scratchy voice. His lips are thick. His thin-irised bronze eyes are close-set. His ears are free-lobed. His pale taupe skin is wrinkled. His hair is dark brown with a touch of gray.</em></p>
    <ol>
        <li style="font-size: 40px"><strong>Religion</strong>
            <ul>
                <li style="font-size: 30px">Lal Helmscradle
                    <ul>
                        <li style="font-size: 20px">Worshiper</li>
                        </ul>
                    </li>
                    <li style="font-size: 30px">Kovest
                        <ul>
                            <li style="font-size: 20px">Ardent Worshiper</li>
                        </ul>
                    </li>
                </ul>
        </li>
        <li style="font-size: 40px"><strong>Membership Status</strong>
            <ul>
                <li style="font-size: 30px">The Axe of Tours
                    <ul>
                        <li style="font-size: 20px">Citizen</li>
                        </ul>
                </li>
                <li style="font-size: 30px">The Smooth Syrup
                    <ul>
                        <li style="font-size: 20px">Member</li>
                        <li style="font-size: 20px">Militia Commander</li>
                        </ul>
                    </li>
                </ul>
        </li>
        <li style="font-size: 40px"><strong>Physical Strengths and Weaknesses</strong>
            <ul>
                <li style="font-size: 30px">Incredibly quick to heal</li>
                <li style="font-size: 30px">Flimsy</li>
                <li style="font-size: 30px">Susceptible to disease</li>
                <li style="font-size: 30px">Quick to tire</li>
            </ul>
        <li style="font-size: 40px"><strong>Likes and Dislikes</strong>
            <ul>
                <li style="font-size: 30px">Likes
                    <ul>
                        <li style="font-size: 20px">Cassiterite</li>
                        <li style="font-size: 20px">Electrum</li>
                        <li style="font-size: 20px">Levin Opal</li>
                        <li style="font-size: 20px">Coral</li>
                        <li style="font-size: 20px">Tapir Bone</li>
                        <li style="font-size: 20px">Brown</li>
                        <li style="font-size: 20px">Gems</li>
                        <li style="font-size: 20px">Floodgates</li>
                        <li style="font-size: 20px">Crutches</li>
                        <li style="font-size: 20px">Food
                            <ul>
                                <li style="font-size: 10px">Lynx</li>
                                <li style="font-size: 10px">Hard Wheat Beer</li>
                                <li style="font-size: 10px">Carambolas</li>
                            </ul>
                        </li>
                </li>
                <li style="font-size: 30px">Dislikes
                    <ul>
                        <li style="font-size: 20px">Large Roaches</li>
                        </ul>
                </li>
            </ul>
        </li>
        <li style="font-size: 40px"><strong>Mental Strengths and Weaknesses</strong>
            <ul>
                <li style="font-size: 30px">Unbreakable will</li>
                <li style="font-size: 30px">Very good creativity</li>
                <li style="font-size: 30px">Ability to focus</li>
                <li style="font-size: 30px">Meager kinesthetic sense</li>
            </ul>
        </li>
        <li style="font-size: 40px"><strong>Personality</strong>
            <ul>
                <li style="font-size: 30px">Little time for forgiveness and will generally seek retribution</li>
                <li style="font-size: 30px">Curious and eager to learn</li>
                <li style="font-size: 30px">Tends to avoid crowds</li>
                <li style="font-size: 30px">Has an active imagination</li>
                <li style="font-size: 30px">Has a tendency to consider ideas and abstractions over practical applications</li>
                <li style="font-size: 30px">Has an active sense of humor</li>
                <li style="font-size: 30px">Rude</li>
                <li style="font-size: 30px">Can handle stress</li>
                <li style="font-size: 30px">Does not easily hate or develop negative feelings</li>
                <li style="font-size: 30px">Prefers to present himself modestly</li>
                <li style="font-size: 30px">Winks when nervous</li>
                <li style="font-size: 30px">Sees working hard as a waste of time</li>
                <li style="font-size: 30px">Values cunning</li>
                <li style="font-size: 30px">Put off by trade or commerce</li>
                <li style="font-size: 30px">Doesn't care about art</li>
                <li style="font-size: 30px">Dreams of raising a family</li>
            </ul>
        </li>
        </ol>
</body>
</html>

Use whatever you want to run the code and see my first and
Logged
I had one get happy again... After producing a bed made from their own husband's body.
I once  had a fort called paddledbottom in the plains of spanking founded by the painful punishment
And so, in a thread about cointainers with usele

Kumquat

  • Bay Watcher
    • View Profile
Re: Learning coding using Dwarf Fortress
« Reply #1 on: April 28, 2016, 04:31:01 pm »

html isn't coding.

You could just as well do formatting in msword or something and save as html. Is that coding? Nope.

Coding happens when someone can ask you 'what does it do?' and you can tell them. With html you can only tell what it is. There is no function, only description.

That doesn't mean that learning html isn't valuable. However it isn't coding.

Of course there are those <script> things. But those aren't html. They're javascript.
Logged

sculleywr

  • Bay Watcher
    • View Profile
Re: Learning coding using Dwarf Fortress
« Reply #2 on: April 28, 2016, 09:48:24 pm »

And it's where I'm starting. HTML, CSS, Javascript, and whatever else I can learn. And it is technically coding. It's just a higher-level language, which relies on the coding underneath it. It is built on the foundation laid by SGML , which is itself built on other things. Just because it's limits are to working with tags doesn't make it not coding. By the pure definition, it is basic coding using high level language. While I don't know how to use stuff, I have been working in IT for years as a field service technician and network operator. You gotta think, as complicated as modding DF is, it basically works on a tag-based setup. I'll be learning Javascript and everything else available on Codecademy, I'm going to find a place to learn C++ and whatever other programming languages I can learn because I'm addicted to studying things. Perhaps by the end of this I can contribute something of value to the DF community in the form of a mod, or a contribution. Hell, half the reason I'm doing this is because I want to play DF with a working economy, sans the bugs that arose from it, and I figure Toady would be happy if someone came up with a way to debug a feature he has stated several times he wants put back into the game. So I've set a goal to learn enough programming and languages to do something like this. I'm not an idea creator. Creativity isn't my strong suit, but I am good at learning how to implement ideas, and the tools for it might be in any programming of any sort, whether it's the basic of HTML or down to binary coding.

And I'm not just defensive on a personal note. I find it quite stupid for people to criticize new people in a field as if their efforts aren't meaningful. I'm an interpreter between languages, a tutor for half a dozen fields in universities. I wouldn't come across a person who was just learning how to fingerspell in ASL and say "That's not really ASL". I wouldn't see a person struggling to learn simple derivative functions and say they aren't really doing calculus, yet. I would expect the same respect from other people who do coding on the lower-level (meaning foundational, not easier) languages that underwrite the codes that I'm learning. Of course I know there is a script underlying the HTML I'm learning. But how can I learn what underlies it if I don't know the function of what underlies it?
Logged
I had one get happy again... After producing a bed made from their own husband's body.
I once  had a fort called paddledbottom in the plains of spanking founded by the painful punishment
And so, in a thread about cointainers with usele

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: Learning coding using Dwarf Fortress
« Reply #3 on: April 28, 2016, 10:28:23 pm »

It's not coding unless you're implementing an algorithm (step by step process.) HTML is just formatting pages, which is no more coding then writing a forum post that includes BB code. Just saying.

JavaScript is. It has variables and conditional statements. It can run differently each time. You can write a JavaScript that writes HTML for you.

« Last Edit: April 28, 2016, 10:38:33 pm by Bumber »
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

King Kitteh

  • Bay Watcher
  • [SAVAGE][CRAZED]
    • View Profile
Re: Learning coding using Dwarf Fortress
« Reply #4 on: April 28, 2016, 10:29:22 pm »

Good job, you can write HTML. Go for it buddy, reach your dreams.

/Thread
Logged
goodnight, speep tighht, don't let the bedbugs bite

Starver

  • Bay Watcher
    • View Profile
Re: Learning coding using Dwarf Fortress
« Reply #5 on: April 28, 2016, 10:49:57 pm »

Learning HTML is good.  Better than relying on WYSIWYG tools that produce absolute dire messes of bloat.  (But it's technically 'markup', in the scriptless form that you're apparently starting with, and Codeacademy should have told you that.)

Others have now said this, I find, before I get to actually post this. It's not your problem, just it is a distinction that you'll probably learn to be pedantic about yourself, in future.


Neat markup, though.  I tend to stick to one or two spaces for each level of indent, personally (but maybe more helps you while you're learning to distinguish levels) and when you get to the part of the course that deals with CSS, you should revisit this sample and arrange to define each level of <LI> depth in the stylesheet document/inline,  to save all those identical/scaling font-size bits.  (e.g. "li" as 40px, "li li" as 30px, etc, but you'll learn how to do that properly.)

And don't be afraid to add in newlines/whitespace in the markup.  That <em>ed line with the description could do with breaking up in the source,  it won't affect its rendering to insert line-wraps in the source text (and,  conversely, you can put <br>s in a non-wrapped bit of the source and it will still appear in the output).

As for that <em>, it's the official successor to the old deprecated italics tag, <i>, but a whole paragraph of emphasis is somewhat straining the purpose of an emphasis. If you do want to emphasise (something which may come out in an altered tone,  for example, in an HTML-to-audio screen-reader for the deaf) use that, but I'd suggest something "font-style: italic"-ish is what you're looking for there. Ditto with <strong>,  previously <b>old, you might want to specify as a bold style.  Right now within the tag, later in the stylesheet bit. (First-level list item contents, only..  You may need to define second+ levels of li as normal, specifically, but that's further down the course.)

The more you can keep content from being obscured by context,  and context from the style, the 'better' the markup.  That's from the POV of future editors of the page, including youself, rather than browsers that usually couldn't care less as long as it's not actually horribly broken, but it might also help if you need to 'scrape' the old page's data with a tool that extracts meaning in some way yet to be determined.

But that's just from sight-reading the source, I'm on a tablet right now and it's not conducive to copying your code into a file to view through a browser to see it rendered.

(Had to edit because italicish and bolded HTML literals needed nobbc tagging!)
« Last Edit: April 28, 2016, 11:02:52 pm by Starver »
Logged

sculleywr

  • Bay Watcher
    • View Profile
Re: Learning coding using Dwarf Fortress
« Reply #6 on: April 28, 2016, 11:06:52 pm »

It's not coding unless you're implementing an algorithm (step by step process.) HTML is just formatting pages, which is no more coding then writing a forum post that includes BB code. Just saying.

JavaScript is. It has variables and conditional statements. It can run differently each time. You can write a JavaScript that writes HTML for you.

Oh, I'm looking forward to learning algorithms. I've used a couple simple ones in a renderer, and looked at a few that implemented more complicated "for" loops, though I'm nowhere near playing with the codes for that. I have a perverse desire to look into recursive algorithms. Lol.

And yes, this is the start. I know there is a lot more out there. But HTML can be used for some coding. It's just not the type of coding that everyone uses for ctual programming. I do know that. But it is something someone who wants to do coding should know.

Learning HTML is good.  Better than relying on WYSIWYG tools that produce absolute dire messes of bloat.  (But it's technically 'markup', in the scriptless form that you're apparently starting with, and Codeacademy should have told you that.)

Others have now said this, I find, before I get to actually post this. It's not your problem, just it is a distinction that you'll probably learn to be pedantic about yourself, in future.


Neat markup, though.  I tend to stick to one or two spaces for each level of indent, personally (but maybe more helps you while you're learning to distinguish levels) and when you get to the part of the course that deals with CSS, you should revisit this sample and arrange to define each level of <LI> depth in the stylesheet document/inline,  to save all those identical/scaling font-size bits.  (e.g. "li" as 40px, "li li" as 30px, etc, but you'll learn how to do that properly.)

And don't be afraid to add in newlines/whitespace in the markup.  That <em>ed line with the description could do with breaking up in the source,  it won't affect its rendering to insert line-wraps in the source text (and,  conversely, you can put <br>s in a non-wrapped bit of the source and it will still appear in the output).

As for that <em>, it's the official successor to the old deprecated italics tag, <i>, but a whole paragraph of emphasis is somewhat straining the purpose of an emphasis. If you do want to emphasise (something which may come out in an altered tone,  for example, in an HTML-to-audio screen-reader for the deaf) use that, but I'd suggest something "font-style: italic"-ish is what you're looking for there. Ditto with <strong>,  previously <b>old, you might want to specify as a bold style.  Right now within the tag, later in the stylesheet bit. (First-level list item contents, only..  You may need to define second+ levels of li as normal, specifically, but that's further down the course.)

The more you can keep content from being obscured by context,  and context from the style, the 'better' the markup.  That's from the POV of future editors of the page, including youself, rather than browsers that usually couldn't care less as long as it's not actually horribly broken, but it might also help if you need to 'scrape' the old page's data with a tool that extracts meaning in some way yet to be determined.

But that's just from sight-reading the source, I'm on a tablet right now and it's not conducive to copying your code into a file to view through a browser to see it rendered.

(Had to edit because italicish and bolded HTML literals needed nobbc tagging!)


Yep. Long way to go. I was wondering what happened to the tags. I simply wanted the first paragraph to appear in italics as a stylistic decision, but I find that styling within HTML is a lot of bodging, so perhaps when I get to the CSS sheets I'll find a better way to do things.
Logged
I had one get happy again... After producing a bed made from their own husband's body.
I once  had a fort called paddledbottom in the plains of spanking founded by the painful punishment
And so, in a thread about cointainers with usele

sculleywr

  • Bay Watcher
    • View Profile
Re: Learning coding using Dwarf Fortress
« Reply #7 on: April 28, 2016, 11:08:04 pm »

Also, since I want to work on things for DF instead of just being a player, knowing which languages will be most useful in DF-related things would be useful.
Logged
I had one get happy again... After producing a bed made from their own husband's body.
I once  had a fort called paddledbottom in the plains of spanking founded by the painful punishment
And so, in a thread about cointainers with usele

NW_Kohaku

  • Bay Watcher
  • [ETHIC:SCIENCE_FOR_FUN: REQUIRED]
    • View Profile
Re: Learning coding using Dwarf Fortress
« Reply #8 on: April 29, 2016, 12:53:41 am »

No need to get too dismissive on technical grounds for someone trying to learn.

Actually, I thought this thread was going to be about learning coding from playing DF. And frankly, I don't think it's all that bad a place to learn, in the sense that you are required to perform highly structured, logical problem solving.  With the standing orders stuff coming in, dwarf management even in the vanilla game will basically be a form of scripting language. 

Understanding the mode of thought required for coding is more important to teach than the strict set of rules for any one given language, as you can pick up the shibboleths of any given specific language fairly quickly if you have a firm understanding of the underlying principles.
Logged
Personally, I like [DF] because after climbing the damned learning cliff, I'm too elitist to consider not liking it.
"And no Frankenstein-esque body part stitching?"
"Not yet"

Improved Farming
Class Warfare

Starver

  • Bay Watcher
    • View Profile
Re: Learning coding using Dwarf Fortress
« Reply #9 on: April 29, 2016, 08:47:15 am »

Actually, I thought this thread was going to be about learning coding from playing DF.

It's what I thought, too, and we're probably some way from OP tying up a (coded) HTML-generator to DFHack's interogative functions to create something like the example page at a click of a mouse, but I'd be happy to help guide them on that (slightly demanding) route, or something similar, and first step might well be Mastery Of Markup! And, even if that's not where we're heading, I repeat that basic hands-on knowledge of markup is good, and although it needn't need DF as a focus, why not?

(I might suggest both a thread-title change and a move out of this DFish sub-forum to one of the more General ones, to allay confusion, but that's not really my place to say...)

Yep. Long way to go. I was wondering what happened to the <i> tags.
They still work (too well!...notice how they 'leak' through the BBCode, and I've had to insert a [nobbc] tag, above, like I had to edit into my original reply) but they're discouraged ('deprecated') in later versions of the HTML standard.

That's because people were using italics to emphasise words, like that, but there was a drive to apply proper meaning to the tags so that emphasised words were clearly marked as emphasis (rather than de facto foreign phrases, or the like) and so the em-tag was brought in to cover that, and others that might cover other cases, and everyone was expected to stress words with em-tags (that may not even be rendered as italics, depending on the renderer) and other things with other tags or formatting hints.

Of course, it largely didn't work. People tended to stick to the italic-tags for italics (whether emphasis, foreign phrase insertion or unquoted 'voices in the head' in dramatic form) or switched to the 'proper' em-tag for everything they wanted italicised (regardless of it being emphasised or not!). The correct solution is to either go into eXtensible Markup Language (XML) territory and seperately define your own <foreign></foreign> tags or (easier, but you're still not there yet) use a span-tag with an id of 'foreignish' (or whatever you want to call it) and then in the stylesheet set style as actual and explicit italics for any spans it finds with a foregnish id to them.

Or in your case, whatever description you would best think to apply to the stylistc description you are making. Such as 'description', 'dwarfdesc' or similar.

But that probably makes no sense, yet! It will later, I'm sure.

For now, continue with what you have. Depending on what browser you use, you might also find an HTML-Validator plugin that you can use to check your own/another page. It won't help you write neat HTML (you've already got that covered, or at least you could have done a lot worse!) but you can sneak a peak at warnings and advice it gives you (e.g. "Italics tag is deprecated, consider using Em tag instead", assuming you slipped back into that mode) and perhaps see what you might want to change. Also (even if the browser handles it Ok) highlighting tags opened but not closed (or vice versa, or both because of an unfortunate typo/half-edit!) that might cause confusion when you expand the page. (Like suddenly get run-on italics.)

Quote
so perhaps when I get to the CSS sheets I'll find a better way to do things.
You will, don't worry.  ;)
Logged

draeath

  • Bay Watcher
  • So it has come to this...
    • View Profile
Re: Learning coding using Dwarf Fortress
« Reply #10 on: May 02, 2016, 10:14:37 pm »

HTML is a markup language - formatting descriptors. It really isn't programming in any way. Now, if you wrote PHP code to generate HTML, that would be a whole different manner.

But it's semantics. Don't let any of this stop you from learning anything you damn well please!

(oh, and scripting is programming even if it's not an ALGOL or Lisp derivative :P)
Logged
Urist McAlchemist cancels extract isotope: interrupted by supercriticality accident.
This kea is so raw it stole my wheelbarrow!

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Learning coding using Dwarf Fortress
« Reply #11 on: May 03, 2016, 11:45:51 pm »

wait does anyone actually think scripting isn't programming

draeath

  • Bay Watcher
  • So it has come to this...
    • View Profile
Re: Learning coding using Dwarf Fortress
« Reply #12 on: May 04, 2016, 12:14:59 am »

Not here, yet, but I've seen folks try to say that on occasion!
Logged
Urist McAlchemist cancels extract isotope: interrupted by supercriticality accident.
This kea is so raw it stole my wheelbarrow!

makeshift 8

  • Bay Watcher
  • Gimli, sitting on 43.
    • View Profile
Re: Learning coding using Dwarf Fortress
« Reply #13 on: May 30, 2016, 04:48:29 pm »

The best place to learn coding IMO is making a game. Learning as you go while making something cool is how I learned. I started with Unity C# and python. HTML isn't really programming, but JS is great for starting your journey in coding.
Logged
Legolas: Final count... fourty-two.
Gimli: Fourty-two? Ohhhh, that's not bad for a pointy eared elvish princeling. I myself am sitting prettily on fourty-three!