GML How to program Credits into the game

Discussion in 'Programming' started by student, Sep 11, 2019.

  1. student

    student Member

    Joined:
    Apr 8, 2019
    Posts:
    3
    I have looked over the internet and I have a general idea on how to code in GML but I just can't work out how to implement credits in to my game. I would appreciate anything like a link to a tutorial or some instructions.

    please and thanks you.
     
  2. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,552
    Just use a global variable. This should have been the first thing on your mind if you had a real idea of how to use GML.

    At the start of the game, set up the global variable:
    Code:
    global.credits = 0;
    
    Then you can get credits like this:
    Code:
    global.credits += 10;
    
    Or spend credits like this (also checking that there's enough):
    Code:
    if (global.credits >= 100) {
      global.credits -= 100;
      /* Actions for spending 100 credits */
    }
    
    Or save the current credits like this (one of many ways):
    Code:
    ini_open(working_directory + "progress.ini");
    ini_write_real("progress", "score", global.credits);
    ini_close();
    
    Or load the saved credits like this (corresponding to the above):
    Code:
    ini_open(working_directory + "progress.ini");
    global.credits = ini_read_real("progress", "score", 0);
    ini_close();
    
     
  3. SnotWaffle Studios

    SnotWaffle Studios Member

    Joined:
    Jun 21, 2016
    Posts:
    288
    Do you mean credits like who did the art, programming, sound, etc.?
     
    DaMuffin likes this.
  4. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,552
    End-game credits is pretty easy too. The simplest form of it uses no more than a few variables and some fairly commonplace functions. A general idea of GML should imply knowing how to do this head-on.

    Create:
    Code:
    text = "Mystery at Faywood Mansion\n\nProgrammer\nAlice Anderson\n\nGraphics\nBob Brown\nCaitlyn Cortland\n\nSound and Music\nDavid Dorset\n\n(C) 2019 Game Developers Inc.";
    scroll_speed = 4;
    
    draw_set_font(fnt_credits);
    text_height = string_height(text);
    x = room_width/2;
    y = room_height;
    
    Step:
    Code:
    y -= scroll_speed;
    if (y <= -text_height) {
      room_goto(rm_menu);
    }
    
    Draw:
    Code:
    draw_set_font(fnt_credits);
    draw_set_colour(c_white);
    draw_set_halign(fa_center);
    draw_text(x, y, text);
    draw_set_halign(fa_left);
    
     
  5. Lord KJWilliams

    Lord KJWilliams Member

    Joined:
    Jul 2, 2018
    Posts:
    109
    What do you mean by "credits" ?... Do you mean a form of fictitious money in your game that your player spends or do you mean a listing of who helped you program ,design, and etc. for your game?
     
    SnotWaffle Studios likes this.
  6. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,639
    The topic tags include "end of game", so I'd say it's safe to assume this is about the wall of text nobody pays attention to.
     
  7. Relic

    Relic Member

    Joined:
    Jun 27, 2017
    Posts:
    720
    Unless you are hoping their is an easter egg, additional cut scene or cheat code right at the end.
     
  8. Lord KJWilliams

    Lord KJWilliams Member

    Joined:
    Jul 2, 2018
    Posts:
    109
    but the topic tags also say "credits" - which could mean a fictitious form of money spent.

    Im sorry, I dont read minds (anymore) - last time I tried that, my brain got indigestion and I got a drinking hangover that lasted 3 times longer than usual the next morning. Now, I just read what people type and hope its what they mean. Its safer in the long run, for my health.
     
    SnotWaffle Studios likes this.
  9. student

    student Member

    Joined:
    Apr 8, 2019
    Posts:
    3
    sorry for the confusion I should of been more clear I meant like TsukaYuriko said the wall of text nobody reads as the games ends

    also thanks FrostyCat for the code its a big help
     
    Lord KJWilliams likes 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