GML Coding Fundamentals in GML Tutorial Series

Discussion in 'Tutorials' started by samspade, Dec 20, 2019.

  1. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,181
    GM Version: GMS 2.2.5 and Prior
    Target Platform: All
    Download: Github Repository
    Links: YouTube Playlist

    Summary:
    A GML tutorial series focused on the basics of coding. A link to the playlist is above and the introduction and first video are below.

    Introduction:


    Tutorial:

     
    Last edited: Jan 4, 2020
  2. Toque

    Toque Member

    Joined:
    May 25, 2017
    Posts:
    1,173
    Nice. Subscribed.
     
  3. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,792
    Some suggestions:
    • DO NOT use curly/smart quotes in code. The compiler won't recognize these as string delimiters.
    • Collapse or reduce the height of the output console. It may get in your way for future tutorials that have more code at once.
    • Increase the font size in the code editor.
    • For this tutorial, I recommend also demonstrating what happens if you mistype a variable name, say cut out or change a character in the variable name. This is another common cause of "variable not set" errors that rookies complain about on the Q&A.
     
    SilentxxBunny, Kezarus, Yal and 4 others like this.
  4. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,181
    Thanks for the comments. I'll start re-recording the videos once I get a better recording set up and implement these changes then. I've made notes in the slides (although the smart quotes note will get added to the data type tutorial and I'll just make sure not to demonstrate it wrong in variables basics).
     
  5. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    4,139
    To add onto this suggestion: pull the output console into a dock on the left or right side, mentioning how you can move the tabs around to suit your workflow... and then later point out how the new vertical layout lets you see much more output at once (which is useful if there's an error, because the error text is usually buried under a dozen or so bookkeeping lines like "not stopping steam since it's not started" - if you don't need to scroll to find the error, it's more painless to fix it).

    (This works really well with Frosty's other suggestion about showing what happens if you mistype a variable name, since now you have an error to show off!)
     
    samspade likes this.
  6. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,181
    Tutorial on Data Types is now up:



    And another short one:

     
    Last edited: Dec 29, 2019
    FrostyCat, kraifpatrik and Toque like this.
  7. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,181
    Tutorial on Variable Scope (also added the introduction tutorial to the original post):

     
  8. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,181
    Enums Tutorial:



    Macros Tutorial:

     
  9. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,181
    Code Style:



    This finishes up the group of subjects I had prepared, so it'll probably be next weekend by the time I put more up. As always, let me know what you think, what things could be improved, if you have questions and so on. My guess is that I will do one more batch and then probably redo some of the earlier videos.
     
    FrostyCat, kraifpatrik and Homunculus like this.
  10. kraifpatrik

    kraifpatrik Member

    Joined:
    Jun 23, 2016
    Posts:
    140
    I've been coding in GML for over a decade and I still enjoy watching these. I like the simple looks of your slides and that the content isn't drawn out and more detailed than it needs to be, plus you have calming voice :D Keep it up!
     
    Kezarus, HayManMarc and samspade like this.
  11. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,181
    New video on conditional statements:

     
    FrostyCat, kraifpatrik and Toque like this.
  12. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    7,070
    Desert Dog, samspade and HayManMarc like this.
  13. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,181
    That would be great. Let me know if there's anything I need to do.
     
  14. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,181
    New video on switch statements:

     
    FrostyCat and kraifpatrik like this.
  15. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,792
    Congratulations on your induction into the offical Learn pages. Hopefully rookies won't overlook them for not doing anything flashy or holding their hand on their "dream game".

    I have taken a look at the videos you posted since the turn of the year. Here is my opinion on the finer points of each topic:

    Data Types
    • enums are actually not a distinct type in GMS 2, just an additional syntax for declaring 64-bit integer constants. If you use typeof() on any enum value, you get int64.
    • Hexadecimals are actually just the literal syntax for int64, again not a distinct type. The actual type is 64-bit integer (int64).
    • It may be helpful to note common sources of non-acceptable quotes for strings, such as rich-text word processors (e.g. Word), copy-and-pastes from PDFs that have not been sufficiently reviewed, or typing aids and IDEs designed for natural language.
    • There is a rift between "fake" Booleans and "genuine" Booleans in GMS 2, which gets unmasked when typeof() and is_bool() are used on them. You can read more about it here and here. This issue won't affect rookies much, but will start becoming a problem when serialization and type-checking get involved.
    • This particular video will likely have to be redone to accommodate lightweight objects and functions for GMS 2.3.
    Using the Manual
    • It is of utmost importance to know how to read individual Manual pages once you've found them, and that's a major omission in this video. On the Q&A, I often link Manual pages for rookies, only for them to talk back to me saying they don't know how to read it. At the very least, they should understand what sections there are on a typical entry page (description, syntax/parameters, returns, example) and what purpose each serves.
    • For novices, it is absolutely crucial that they learn what NOT to look for in the Manual. It is a reference for definitions, and definitions only. A lot of them write off the Manual because they have inappropriate expectations from the manual (e.g. full tutorials and background knowledge). That are still Google material on the most part. In particular, novices should be encouraged to not restrict themselves to GM-specific resources for background theory on things like trigonometry and networking.
    • The built-in search tab is pretty marginal due to its need for exact wording matches. For general searches, I usually just go on Google and type <query> site:docs2.yoyogames.com. That only works when I'm using the latest stable version, though. For example, if the GMS 2.3 open beta comes up, I would have to revert to the built-in tabs because the online documentation won't have the new material.
    • Direct lookups can also be brought up with the F1 key when the cursor is over a built-in function/variable. This can be useful for on-the-go laptop setups that don't come with a middle click.
    Scope
    • It would be clearer to a novice if you summarize what kinds of context each scope is generally applicable to: Global for shared properties of the environment, instance for non-shared properties of individual instances, local for temporary values.
    • For future tutorials involving for loops and scripts, you should be strict in using local variables for iteration variables and temporary results. Viewing local variables as mainly a nice-to-have memory saver is a disturbing attitude that I don't think this video adequately addresses. I see stuff like this on the GMC all the time, sometimes even from people purporting to be instructors:
      Code:
      for (i = 0; i < 7; i++)
      
      That i will stick around to clutter up the instance scope at best, and cause unexpected problems like these at worst. And there is next to no community awareness of it.
    Enums
    • Note that the enum+array trick will be superceded by structs with the GMS 2.3 upgrade, except for continuing work with legacy code.
    Macros
    • Best practice note: Because macros act like copy-and-paste replacements, expressions containing operators should always be enclosed in brackets to avoid unexpected issues later with order of operation. Here is a pathological example:
    Code:
    #macro foo 1+5
    show_message("Foo is " + string(foo)); //6
    show_message("Expected 3*foo = 3*6 = 18, got " + string(3*foo)); //8
    
    Code Style
    • Typical tab sizes are 4 and 2. 5 (shown at 1:04) is generally too much.
    • "Loose GML" is one area that I often question coverage of in tutorials, precisely because they come apart at novice-unexpected times. For example, when you talked about "GML Flexibility", you didn't say that the first and third examples will become invalid if there are multiple actions being covered by the if block. I see rookies doing Python-esque stuff on GML all the time and then whine about code not working.
    Conditional Statements
    • It may be useful as an appendix to show what conditional statements look like as written in Allman style.
    • It should be mentioned that else should always be used over the if (A) { ... } if (!A) { ... } anti-pattern. Rookies do the latter quite frequently and cause a load of unexpected problems down the road.
     
    Last edited: Jan 11, 2020 at 7:51 PM
    Nocturne likes this.
  16. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,181
    Thank you. I appreciate the comments quiet a bit.

    The only question I have on the above is regarding data types. The manual lists both as distinct data types. So even if type_of returns int64 I thought it would be better to refer to them as the manual does. Would it be possible for both to be true? e.g. type_of returning int64 but other systems in GML treating them as distinct datatypes in some manner? Either way, I can note this.

    I'm still debating the best way to incorporate changes into the videos. Some, I'm going to redo (once 2.3 comes out I'll redo necessary videos and tag older ones with a legacy note). The variable basics video for example I'll probably redo in the next couple weeks. For others I might simply put correction text on the screen or pin a comment with corrections and additions to the video. But I will be working on incorporating all the suggestions I can in the upcoming weeks.
     
  17. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,181
    New video on boolean logic:

     
    FrostyCat likes this.
  18. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,792
    I like this one from a technical standpoint, and thank you for the referral links.

    As always, here are my comments:
    • Since GMS 1.2, all case expressions must either be constants or expressions that can evaluate down to a constant at compile time. This important restriction has not been described in the switch video.
    • Consider using = to denote the identities between 3:39-5:25 instead of tables. Visually, these can be read 2 ways (row-wise and column-wise), and one of those ways is wrong.
    • Consider including definitions in your end-of-video summaries going forward (e.g. && returns true if both operands are true, false otherwise). This helps reinforce understanding, especially in longer videos where important content are spaced farther apart in time.
     
    Nocturne likes this.
  19. Toque

    Toque Member

    Joined:
    May 25, 2017
    Posts:
    1,173
    Nice videos. I find the red text harder to read against black. I like that they are simple.
     
    Last edited: Jan 13, 2020 at 3:05 PM
  20. SilentxxBunny

    SilentxxBunny Epsilon

    Joined:
    Jun 21, 2016
    Posts:
    131
    This is the single greatest thread I've ever stumbled into. Thank you. Sincerely.
     
  21. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,181
    New video on operators up:

     
    Toque and FrostyCat like this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice