【GAMEMAKER】Saving

Information about object: obj_splash

Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object

Create Event:
execute code:

///set up stats
//Load Data From Save
ini_open("save.ini");
global.stats[1,1]="Magic";
global.stats[1,2]=ini_read_real("Stats", "Magic", 4);

global.stats[2,1]="Kindness";
global.stats[2,2]=ini_read_real("Stats", "Kindness", 4);

global.stats[3,1]="Evilness";
global.stats[3,2]=ini_read_real("Stats", "Evilness",2)

global.stats[4,1]="Strength";
global.stats[4,2]=ini_read_real("Stats", "Strength", 4);

global.stats[5,1]="Wisdom";
global.stats[5,2]=ini_read_real("Stats", "Wisdom", 0);

global.stats[5,1]="Charisma";
global.stats[5,2]=ini_read_real("Stats", "Charisma", 1);

global.upgrades=ini_read_real("Stats", "Upgrades", 8);

global.quest1=ini_read_real("Quest", "1", true);

global.pirate1_x=ini_read_real("Pirates", "1x", 350);
global.pirate1_y=ini_read_real("Pirates", "1y", 640);

global.gold=ini_read_real("Stats", "Gold", 200);


ini_close();
//goto main room
room_goto(room_saving);

Information about object: obj_button
Sprite: spr_button
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

//set up
image_speed=0;
image_index=0;
Step Event:
execute code:

///mouse button
if mouse_check_button_pressed(mb_left) && position_meeting(mouse_x, mouse_y, id)
{
    if global.upgrades>0 && global.stats[my_id,2]<10
    {
        //upgrade
        global.upgrades--;
        global.stats[my_id,2]++;
    }
}
Draw Event:
execute code:

//draw button
draw_self();
//set text drawing
draw_set_halign(fa_center);
draw_set_valign(fa_middle);
//draw the text 
draw_set_halign(fa_left);
draw_text(50,my_id*100,global.stats[my_id,1]);

//draw red sprite - not the quickest approach, but easy to understange
for (var loop=1; loop < 11; loop += 1)
{
    draw_sprite(spr_info,1,150+loop*40,my_id*100)
}

//draw yellow sprite
for (var loop=1; loop <= global.stats[my_id,2]; loop += 1)
{
    draw_sprite(spr_info,0,150+loop*40,my_id*100)
}

//draw button text
draw_set_halign(fa_center);
if global.stats[my_id,2]<10 && global.upgrades>0
{
    image_index=0;
    draw_text(x,y,"Available");
}
else if global.stats[my_id,2]==10
{
    image_index=1;
    draw_text(x,y,"Maxed Out");
}
else
{
    image_index=1;
    draw_text(x,y,"Not Available");
}



Information about object: obj_setup_buttons_and_hud
Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

///create buttons
for (var loop = 1; loop < 6; loop += 1)
{
    button=instance_create(700,100*loop,obj_button);
    button.my_id=loop
}
Step Event:
execute code:

///for testing
if keyboard_check_pressed(ord('R'))
{
    show_message("Saved - Restaring");
    game_restart();
}

if keyboard_check_pressed(ord('S'))
{
    scr_save_data();
    show_message("All Data Saved");
}

if keyboard_check_pressed(ord('Q'))
{
    global.quest1=!global.quest1;
}

if keyboard_check_pressed (ord('G'))
{
    global.gold+=100;
}
if keyboard_check_pressed (ord('X'))
{
    global.upgrades+=5;
}
Draw Event:
execute code:

///for testing
draw_set_halign(fa_left);

draw_text(100,50,"You Have "+string(global.upgrades)+" Upgrade Points - Press R To Restart Example#Arrow Keys To Move Character#S To Save Data - A D move pirate - Q Toggle Quest -#G For More Gold  X For More Upgrade Points");

if global.quest1 draw_text(400,700,"Quest Completed");
else
draw_text(400,700,"Quest Is Not Completed");

draw_text(400,720,"Gold "+string(global.gold));

Information about object: obj_pirate
Sprite: spr_pirate
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

x=global.pirate1_x;
y=global.pirate1_y;
Step Event:
execute code:

if keyboard_check(ord('A'))
{
    x--;
}
if keyboard_check(ord('D'))
{
    x++;
}

if x<64 x=64;
if x>room_width-64 x=room_width-64;

No comments:

Contact Form

Name

Email *

Message *