• Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!

GML How to program Credits into the game

student

Member
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.
 

FrostyCat

Member
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();
 

FrostyCat

Member
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);
 
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?
 

Relic

Member
Unless you are hoping their is an easter egg, additional cut scene or cheat code right at the end.
 
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.
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.
 

student

Member
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
 
Top