Results 1 to 11 of 11
  1. - Top - End - #1
    Ogre in the Playground
     
    Chainsaw Hobbit's Avatar

    Join Date
    Dec 2009
    Location
    Avatar by Ceika
    Gender
    Male

    Default Learning JavaScript ...

    I am a homeschooled high school student, and I have been given an assignment to learn JavaScript. I have opted to strike out on my own, and learn what I need to know from the internet.

    What I would like to do, as an exercise, is make a character builder for some sort of tabletop roleplaying game - probably something simple and d20-based like Basic Fantasy or Castles & Crusades.

    I can learn the basic principals of the language from internet tutorials, but I would like some help deciding how to approach making a character builder. How should I structure it? How long can I expect it to take? What are some possible pitfalls?

    Thanks in advance!

  2. - Top - End - #2
    Firbolg in the Playground
    Join Date
    Aug 2005
    Location
    Mountain View, CA
    Gender
    Male

    Default Re: Learning JavaScript ...

    JavaScript can't really stand on its own, it is a language used to add certain types of features to things mostly built with another language. You are going to have to learn at least the basics of HTML and the Document Object Model (DOM) as well, possibly CSS and some other things depending on how ambitious you get with it.

    If you want the characters generated by this to be stored and saved anywhere, you will have to learn some non-JavaScript means of doing that because JavaScript can't do it.

    JavaScript has one enormous pitfall in that, while there is an official standard for the language, it is not followed in every detail by every browser. Somewhere along the line, you will almost certainly run into something that works in Internet Explorer but not Firefox, or vice versa, or some other combination with other browsers. It may even differ between consecutive versions of the same browser.

    For design approach, think about the steps you would go through for character creation on paper, the order, and what depends on what. In general, if a later part depends on an earlier part then you will want the section of web page dealing with the later part to be not present, hidden, or disabled/blank until the earlier part is completed. If you want to get in the habit of acting as if security matters (which it obviously doesn't for this, but having it as a habit will help if you ever have a future project where security does matter), "not present" is the strongly preferred (but harder to implement) option. This is because browser plugins and special tools on the client machine can alter your web page in almost arbitrary ways, and if all they have to do is clear one hidden/disabled flag to bypass your lockout then it's really easy to do. Worrying about security is an optional extra credit type option on a project like this, though, so don't feel like you have to do it.

    If at any point you find yourself using JavaScript to construct whole sections of a web page, stop, take a deep breath, and tear out that part of the code and replace it with a link/redirection/whatever to a separate page.

    Do not, ever, under any circumstances, use JavaScript to implement the behavior of a link. There are standard HTML options for that, and using JavaScript instead prevents several highly developed and useful standard features of most browsers from working. This will annoy many users of your web pages. If disabling those features is for some reason desirable, think long and hard about why and whether the reasons are really that important.

    In a project like this, I would expect JavaScript to be useful primarily for A) automatically calculating numbers and fields that are dependent on others, B) filling in the list of available choices for a later step that is dependent on an earlier step, and C) any minor changes to the page you would like to happen while a character is in progress without having to reload the page from the server. Category C should be quite small unless you are getting very fancy indeed. The vast majority of everything else should be handled with HTML and maybe CSS.
    Saberhagen's Twelve Swords, some homebrew artifacts for 3.5 (please comment)

    Archives:
    Spoiler
    Show
    Isstinen Tonche for ECL 74 playtesting.
    Team Solars: Powergaming beyond your wildest imagining, without infinite loops or epic. Yes, the DM asked for it.
    Arcane Swordsage: Making it actually work (homebrew)

  3. - Top - End - #3
    Dwarf in the Playground
     
    Grindle's Avatar

    Join Date
    Feb 2013

    Default Re: Learning JavaScript ...

    I'd like to say that some internet Javascript tutorials are pretty low quality. (In particular, avoid W3Schools).

    Also, some possibly helpful links:

    http://dev.opera.com/articles/view/1...dards-cur/#toc

    https://developer.mozilla.org/en-US/docs

    http://eloquentjavascript.net/

    http://javascript.crockford.com/javascript.html
    My HTML to BB Code converter. Paste into the top box from any word processor/online source. No more tables by hand!

  4. - Top - End - #4
    Titan in the Playground
     
    BlackDragon

    Join Date
    Feb 2007
    Location
    Manchester, UK
    Gender
    Male

    Default Re: Learning JavaScript ...

    Is it definitely JavaSCRIPT you're supposed to learn? Because the thing you said you want to do sounds more like a job for full-blown Java--as douglas points out, Javascript is really intended to add facilities to other languages and programs, not stand alone as a programming language.

  5. - Top - End - #5
    Ogre in the Playground
     
    Chainsaw Hobbit's Avatar

    Join Date
    Dec 2009
    Location
    Avatar by Ceika
    Gender
    Male

    Default Re: Learning JavaScript ...

    Quote Originally Posted by factotum View Post
    Is it definitely JavaSCRIPT you're supposed to learn? Because the thing you said you want to do sounds more like a job for full-blown Java--as douglas points out, Javascript is really intended to add facilities to other languages and programs, not stand alone as a programming language.
    My father was rather specific. I do know a small amount of HTML, though.

  6. - Top - End - #6
    Dwarf in the Playground
     
    Grindle's Avatar

    Join Date
    Feb 2013

    Default Re: Learning JavaScript ...

    I think you could use Javascript to make a character builder perfectly well. For examples of a site using Javascript for D&D related uses, see http://www.d20srd.org/extras/d20encountercalculator/ or http://www.d20srd.org/extras/d20dicebag/.
    My HTML to BB Code converter. Paste into the top box from any word processor/online source. No more tables by hand!

  7. - Top - End - #7
    Ogre in the Playground
    Join Date
    Jan 2012

    Default Re: Learning JavaScript ...

    It won't be pretty, but you could certainly do it in Javascript.

    First, how much control should the user have over the final result? Keep in mind that the more control they have, the harder it will be to program.

    Quote Originally Posted by Grindle View Post
    I think you could use Javascript to make a character builder perfectly well. For examples of a site using Javascript for D&D related uses, see http://www.d20srd.org/extras/d20encountercalculator/ or http://www.d20srd.org/extras/d20dicebag/.
    Same principle, yes, but a character generator is just a wee bit more complicated, especially where player characters are involved.
    Last edited by Grinner; 2013-03-14 at 12:35 PM.

  8. - Top - End - #8
    Ogre in the Playground
    Join Date
    Oct 2009

    Default Re: Learning JavaScript ...

    Javascript is really an odd choice in my opinion for a first programming language to learn.

    Most of the heavy lifting will more or less be done in another language with javascript just doing some calculations from user inputs etc

    If you (or more your father) is dead set on java script (instead of say java or c# or python) well be prepared to learn none javascript stuff too for that project.

    Quote Originally Posted by douglas View Post
    If you want the characters generated by this to be stored and saved anywhere, you will have to learn some non-JavaScript means of doing that because JavaScript can't do it.
    As for the storing of a user character couldnīt you use json for serializing/deserializing and store the string in the local storage?
    Never done anything with javascript so its just a guess what might work
    Last edited by Emmerask; 2013-03-14 at 12:53 PM.

  9. - Top - End - #9
    Titan in the Playground
     
    Flickerdart's Avatar

    Join Date
    Mar 2008
    Location
    Pittsburgh
    Gender
    Male

    Default Re: Learning JavaScript ...

    It really depends on what you mean by "character builder". If it's something like what MythWeavers presents - a character sheet with some automatically calculated values - then that's mostly HTML and you barely need any Javascript at all. If you actually want to take people through the steps of building a character, that's still HTML, but there will be more scripting involved.

    The only way to do it in "pure" JS is using HTML5 Canvas to construct all the bits, but Canvas isn't really intended for that.
    Quote Originally Posted by A_Moon View Post
    How many times, when the Fighter says "I draw my sword", did you just want to smack that cheating-optimizer in the face and say "No! You don't draw your sword! You draw Orcus!". When the Cleric says "I run away from Orcus!": "No! You run into Orcus! Rogue tries to hide? He hides behind Orcus! The bard in a tavern on the other side the town tries to order a drink? How about a nice frothy mug of Orcus?

  10. - Top - End - #10
    Ettin in the Playground
     
    Kobold

    Join Date
    May 2005
    Location
    Somerville, MA
    Gender
    Male

    Default Re: Learning JavaScript ...

    Quote Originally Posted by douglas View Post
    JavaScript can't really stand on its own, it is a language used to add certain types of features to things mostly built with another language. You are going to have to learn at least the basics of HTML and the Document Object Model (DOM) as well, possibly CSS and some other things depending on how ambitious you get with it.

    If you want the characters generated by this to be stored and saved anywhere, you will have to learn some non-JavaScript means of doing that because JavaScript can't do it.
    By itself I agree. But presentation, DOM, and file saving can be bypassed if instead of writing the script in straight up javascript you do it as an extension for a Google Documents spreadsheet. That'll take care of storage and presentation. From what I've seen of the API, it's going to be a steeper learning curve than just javascript, but it'll be focused on one thing instead of divided over javascript, HTML, and maybe a PHP backend.
    If you like what I have to say, please check out my GMing Blog where I discuss writing and roleplaying in greater depth.

  11. - Top - End - #11
    Dwarf in the Playground
     
    Grindle's Avatar

    Join Date
    Feb 2013

    Default Re: Learning JavaScript ...

    Quote Originally Posted by douglas View Post
    If you want the characters generated by this to be stored and saved anywhere, you will have to learn some non-JavaScript means of doing that because JavaScript can't do it.
    Here's an simple example I've made of how you can use Javascript to basically do file-saving: http://jsfiddle.net/a_e_m/e9wcW/show/
    (Users could bookmark the page/save it to a file/print it out. Here's a simple example character.)

    There are two files involved, a form page and a template page. When submitted, the form is sent (via GET request) to the template, which fills itself out using Javascript.

    Pros:
    • simple to implement, no dealing with servers, could work offline
    • no learning another programming language

    Cons:
    • long enough URLs could cause problems in some browsers
    • Javascript required for the character sheet (not really a reasonable con, because the character generator would be javascript-dependent too)
    Last edited by Grindle; 2013-03-19 at 03:02 PM.
    My HTML to BB Code converter. Paste into the top box from any word processor/online source. No more tables by hand!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •