what's wrong with my daily reward system?

G

giannis196

Guest
hello everyone!!

so, i tried to make a daily reward system where if the gets 1000000 points daily once a day when the game starts and notice the day changed
here is my code in load game script:


GML:
function scr_loadgame(){
if (file_exists("User.sav"))
{
ini_open("User.sav")
global.date = ini_read_real("Save1", "date", 0);
global.month = ini_read_real("Save1", "month", 0);
global.year = ini_read_real("Save1", "year", 0);
show_message(int64(global.year));
global.Money = ini_read_real("Save1", "Money", 0);
global.efficiency = ini_read_real("Save1", "efficiency", 5);
global.speed = ini_read_real("Save1", "speed", 50);
global.off = ini_read_real("Save1", "off", 1);
if(global.year > int64(current_year))
{
            global.Money += 100000000;
            global.year = int64(current_year);
            global.month = int64(current_month);
            global.date = int64(current_day);
            show_message("you have been awarded with 100000000 money for your today login");
}
if(global.month > int64(current_month))
{
            global.Money += 100000000;
            global.year = int64(current_year);
            global.month = int64(current_month);
            global.date = int64(current_day);
            show_message("you have been awarded with 100000000 money for your today login");
}
if(global.date > int64(current_day))
    {
            global.Money += 100000000;
            global.year = int64(current_year);
            global.month = int64(current_month);
            global.date = int64(current_day);
            show_message("you have been awarded with 100000000 money for your today login");
    }
}else{
global.Money = 0;
global.efficiency = 5;
global.speed = 50;
global.off = 1;
global.date = int64(current_day);
global.month = int64(current_month);
global.year = int64(current_year);
}

}
ini_close();

and here is my code on savegame script:


GML:
// Script assets have changed for v2.3.0 see
// https://help.yoyogames.com/hc/en-us/articles/360005277377 for more information
function scr_savegame(){
if(file_exists("User.sav")) file_delete("User.sav");


ini_open("User.sav")
ini_write_real("Save1","Money", global.Money);
ini_write_real("Save1","efficiency", global.efficiency);
ini_write_real("Save1","speed", global.speed);
ini_write_real("Save1","off", global.off);
ini_write_real("Save1", "date", global.date);
ini_write_real("Save1", "month", global.month);
ini_write_real("Save1", "year", global.year);
ini_close();
}
it loads and saves successfully but the daily bonus doesn't work.
btw the int64(current_day); i also tried it with string(current_day); first which it didn't worked either.
 

Nidoking

Member
So...

If it's a later year, give the bonus and set the date to current.
If it's a later month, give the bonus and set the date to current.
If it's a later day, give the bonus. If it's not a later day, for example, if it was a later year or month and the date has been set to current, eliminate all of the bonuses.

I don't know about any of the rest of your logic, but it looks like what you have only works (accidentally, at that) if it's later in the same month of the same year.

Have you looked at the ini file to make sure the int64s are written properly?
 

chamaeleon

Member
Too much micromanaging of individual date variables in my opinion
GML:
function next_reward_threshold() {
    var now = date_current_datetime();
    var threshold = date_inc_day(now, 1);
    var year = date_get_year(threshold);
    var month = date_get_month(threshold);
    var day = date_get_day(threshold);
    return date_create_datetime(year, month, day, 0, 0, 0);
}

function save_next_threshold() {
    ini_open("User.sav");
    ini_write_real("User1", "rewardtimestamp", next_reward_threshold());
    ini_close();
}

function check_threshold() {
    var now = date_current_datetime();
    
    ini_open("User.sav");
    var threshold = ini_read_real("User1", "rewardtimestamp", 0);
    ini_close();
    
    if (date_compare_datetime(now, threshold) >= 0) {
        show_message("You have been rewarded with lots of money");
        save_next_threshold();
    }
}
 
G

giannis196

Guest
So...

If it's a later year, give the bonus and set the date to current.
If it's a later month, give the bonus and set the date to current.
If it's a later day, give the bonus. If it's not a later day, for example, if it was a later year or month and the date has been set to current, eliminate all of the bonuses.

I don't know about any of the rest of your logic, but it looks like what you have only works (accidentally, at that) if it's later in the same month of the same year.

Have you looked at the ini file to make sure the int64s are written properly?
Where is the .ini file? where i can find it?
I don't see it in the folder of my project.

Edit: i just checked the value of global.year and it have got 0 instead of 2020
but why 0?
from where does it takes the year, shouldn't it be 2020?
 
Last edited by a moderator:
Top