Game Maker Studio: How to Save & Load Coins you Pick Up, Room, & Score?

Channel:
Subscribers:
268
Published on ● Video Link: https://www.youtube.com/watch?v=Xg4x5pDNJVA



Duration: 16:16
152 views
0


GMS File: https://rb.gy/kg1fz7

Note: Do not make global objects (Blue Question Marks) Persistent, because this game uses Test Instance Count for each room. This drop in works like this, once you collect all coins, it will jump to the next room. Well... if you set the global objects to Persistent, the last room will come up error, due to the fact, there are no coins in room. So last room will never show up, so don't make global objects Persistent. So the last room will have no global objects, with Persistent not checked. Note: You can mark global objects Persistent, and load and save will work, but do not use Test Instance Count and you should be okay.


scoresave, Depth: -500 do not make it Persistent.

Events:

Game Start

Actions:

ini_open("coin14.ini") ///Can change the name to what you want the save ini file as. If you want to start from beginning, before the save, just change out all the coin14's to like coin15, coin16, so the change happens and you restart the game.

global.score1 = ini_read_real("save","score1",0); /////For the score, you can choose a name, example global.scorecount, global.scorego, just be sure that the other code in the global events match, or the code will not work.

ini_close();

set_score_room, Depth: -500 do not make it Persistent.

Events:

Game Start

Actions:

global.score1=0

o_draw, Depth: -500 do not make it Persistent.

Events:

Draw

Actions:

draw_set_color(c_white)
draw_set_font(font0)


{

draw_text(view_xview[0]+50,view_yview[0]+70, string(global.score1) )

}

/////The above code, draws the score text on screen and places it where you want it in the rooms. Draw_Set_Font is the font you choose as you're design.

obj_coin

Events:

Create

Actions:

ini_open("coin14.ini") ///This code is reading the Save part, when you take a coin, its reading the real about to be saved. So when you come back to room the coins taken will still be destroyed.
var taken = ini_read_real("coins",string(id), -1);


ini_close();

if(taken !=-1) instance_destroy();

Left Pressed

Actions:

ini_open("coin14.ini") ///This code is writing and saving the objects pickup, and save the room & score points.
ini_write_real("coins",string(id), 1);
ini_write_real("save","score1",global.score1);


ini_close();


instance_destroy();




Other Videos By MC Designs


2021-04-16Game Maker Studio: How to Collect Rewards, once you past Certain Amount of Time?
2021-04-10Game Maker Studio: (Part1) How to Collect Coins to Buy a Item?
2021-04-10Game Maker Studio: How to Warp & Destroy at Position?
2021-04-03Game Maker 8.1: How to Find a Map, & Make Visible on Screen?
2021-03-27Game Maker Studio: (Part 2) How to Save, & Load you're Inventory?
2021-03-21Game Maker Studio: (Part 1) How to Save, Load You're Room, & Mark Inventory Persistent?
2021-03-20Game Maker Studio: How to Move, Parenting, & Void Getting Stuck in Walls?
2021-03-13Game Maker Studio: (Part 2) Randomly Choosing Set of Numbers & Images?
2021-03-13Game Maker Studio: (Part 1) How to Gain, Take Away, & Move to Next Room?
2021-03-07Game Maker Studio: How to Gain 50 Coins, then Restart Game?
2021-03-06Game Maker Studio: How to Save & Load Coins you Pick Up, Room, & Score?
2021-02-27Game Maker 8.1: How to Create a Mini Map, & find Enemies & Items?
2021-02-20Game Maker Studio: How to Create Googly Eyes, when Getting Hit?
2021-02-16Game Maker Studio: How to Create a Easy Inventory System for Android?
2021-02-13Game Maker Studio: How to Create a Easy Inventory System for PC?
2021-02-12Game Maker Studio: How to Angle Shake an Object, when getting Hit?
2021-02-12Game Maker 8.1: How to Open a Door, once Equal Number of Prisoners are Saved?
2021-02-12Game Maker 8.1: How to Scale Buttons, when Pressed?
2021-02-06Game Maker 8.1: How to Collect Key, Messages, Open Cell, & Save a Prisoner?
2021-01-30Game Maker Studio: How to Shake an Object, when getting Hit?
2021-01-23Game Maker Studio: How to Unlock Rooms?



Tags:
game
maker
studio
computer
pc
android
device
how
show
learn
teach
pick
up
room
score
save
load
instance
count
variable
global
set
var
relative
create
execute
piece
code
ini
open
taken
id
string
real
write
button
destroy
if
draw
font
text
point
points
gain
come
back
exit
pickup
depth
obj
object