• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Solved]Gettime function in Pokemon Emerald

  • 17
    Posts
    333
    Days
    • Seen May 25, 2024
    I'm looking for a way to have a script/event that depend on the time.
    I looked in crystaldust scripts and found this :
    script Route35_EventScript_Dirk {
    lock
    faceplayer
    gettime
    if (var(VAR_0x8002) == TIME_NIGHT)
    {
    trainerbattle_single(TRAINER_DIRK, Route35_Text_DirkIntro, Route35_Text_DirkDefeated)
    msgbox(Route35_Text_DirkPostBattle)
    }
    else
    {
    msgbox("Your POKéMON look pretty tough.\n"
    "You could go anywhere safely.")
    }
    release
    }
    So I tried to implement the gettime function in my code, but it doesn't assemble in the end. I do have the following error :
    data/maps/Mossdeep_SeaGate2/scripts.inc: Assembler messages:
    data/maps/Mossdeep_SeaGate2/scripts.inc:9: Error: non-constant expression in ".if" statement
    This makes me wondering if the gettime function is well used this way, or if there is another way to run a script/event based on the time.

    I hope that my question is clear and hope I'll get some help.

    Regards
     

    Lunos

    Random Uruguayan User
  • 3,116
    Posts
    15
    Years
    I'm looking for a way to have a script/event that depend on the time.
    I looked in crystaldust scripts and found this :

    So I tried to implement the gettime function in my code, but it doesn't assemble in the end. I do have the following error :

    This makes me wondering if the gettime function is well used this way, or if there is another way to run a script/event based on the time.

    I hope that my question is clear and hope I'll get some help.

    Regards
    By default, the gettime scripting command retrieves the value of the current hour, minute and second at the time of use and stores them inside the vars 0x8000, 0x8001 and 0x8002.
    https://github.com/pret/pokeemerald/blob/master/asm/macros/event.inc#L322
    https://github.com/pret/pokeemerald/blob/master/src/scrcmd.c#L696-L703

    CrystalDust modifies it a bit; instead of saving the amount of seconds in the var 0x8002, it saves the current part of a day retrieved by a function labeled GetCurrentTimeOfDay.
    https://github.com/Sierraffinity/CrystalDust/blob/master/src/scrcmd.c#L705-L713
    https://github.com/Sierraffinity/CrystalDust/blob/master/include/constants/day_night.h#L13-L16

    If you want it to behave the same, you'll have to apply the same type of changes, and needless to say, you'll have to define the same constant labels linked above.
    If you don't want to do that, you can do something like:
    Code:
    gettime
    if (var(VAR_0x8000) >= 0 && var(VAR_0x8000) < 12)
    {
        insert_rest_of_the_code_here
    Similar to how the vanilla codebase handles time-based checks in places such as GetEvolutionTargetSpecies, and that should work just fine.
    Note that the aforementioned function uses constant labels these days, but I think that they can't be used inside overworld scripts due to being defined in include/pokemon.h as opposed to include/constants/pokemon.h. The constants in question are NIGHT_EVO_HOUR_BEGIN and NIGHT_EVO_HOUR_END.
    I'm just speaking from memory though, feel free to try them out instead of hardcoding 0 and 12 if you want to.
     
  • 17
    Posts
    333
    Days
    • Seen May 25, 2024
    @Lunos Thanks for the answer !
    While the hardcoded way work, I made a few changes in the files in order to have something working like in crystal dust but it doesn't seems to work (still have the same error).
    I'll try to figure how to correct that, since it way another way, I'm fine with that.

    Thanks a lot!
     
  • 461
    Posts
    6
    Years
    • Seen yesterday
    @Lunos Thanks for the answer !
    While the hardcoded way work, I made a few changes in the files in order to have something working like in crystal dust but it doesn't seems to work (still have the same error).
    I'll try to figure how to correct that, since it way another way, I'm fine with that.

    Thanks a lot!
    You didn't actually post your script so I can't say for sure, but I would guess that the error is caused by you using some undefined constant in your script like TIME_NIGHT.
     
  • 17
    Posts
    333
    Days
    • Seen May 25, 2024
    You didn't actually post your script so I can't say for sure, but I would guess that the error is caused by you using some undefined constant in your script like TIME_NIGHT.
    You are right, I should have put the code here, just in case.

    So here is a part of a code in my file dns.c located in the src repo

    u8 GetCurrentTimeOfDay(void)
    {
    return GetDnsTimeLapse(gLocalTime.hours);
    }
    //Returns Dns time lapse
    u8 GetDnsTimeLapse(u8 hours)
    {
    if (hours < MIDNIGHT_END_HOUR)
    return TIME_MIDNIGHT;
    else if (hours < DAWN_END_HOUR)
    return TIME_DAWN;
    else if (hours < DAY_END_HOUR)
    return TIME_DAY;
    else if (hours < SUNSET_END_HOUR)
    return TIME_SUNSET;
    else if (hours < NIGHTFALL_END_HOUR)
    return TIME_NIGHTFALL;
    else
    return TIME_NIGHT;
    }
    //returns the filter to use depending on RTC time.
    static u16 GetDNSFilter()
    {
    u8 hours = gLocalTime.hours;
    u8 minutes = gLocalTime.minutes;
    switch(GetDnsTimeLapse(hours))
    {
    case TIME_MIDNIGHT:
    if (hours < 1)
    return gMidnightFilters[minutes >> 3];
    else
    return gMidnightFilters[7];
    case TIME_DAWN:
    return gDawnFilters[minutes >> 1];
    case TIME_DAY:
    return gDayFilter;
    case TIME_SUNSET:
    return gSunsetFilters[minutes >> 1];
    case TIME_NIGHTFALL:
    return gNightfallFilters[minutes >> 1];
    case TIME_NIGHT:
    return gNightFilter;
    }
    return 0;
    }

    Here is the code of the dns.h file located in the include repo
    #ifndef GUARD_DNS_UTILS_H
    #define GUARD_DNS_UTILS_H
    #define DNS_PAL_EXCEPTION FALSE
    #define DNS_PAL_ACTIVE TRUE
    struct LightingColour {
    u8 paletteNum;
    u8 colourNum;
    u16 lightColour;
    };
    struct DnsPalExceptions {
    bool8 pal[32];
    };
    u8 GetCurrentTimeOfDay(void);
    u8 GetDnsTimeLapse(u8 hours);
    void DnsTransferPlttBuffer(void *src, void *dest);
    void DnsApplyFilters();
    #endif /* GUARD_DNS_UTILS_H */
    And here is the code of the dns.h file located in the include/constants repo
    #ifndef GUARD_CONSTANTS_DNS_UTILS_H
    #define GUARD_CONSTANTS_DNS_UTILS_H
    #define TIME_MIDNIGHT 0
    #define TIME_DAWN 1
    #define TIME_DAY 2
    #define TIME_SUNSET 3
    #define TIME_NIGHTFALL 4
    #define TIME_NIGHT 5
    #endif /* GUARD_CONSTANTS_DNS_UTILS_H */
    I also add this in the scrcmd file
    bool8 ScrCmd_gettime(struct ScriptContext *ctx)
    {
    RtcCalcLocalTime();
    gSpecialVar_0x8000 = gLocalTime.hours;
    gSpecialVar_0x8001 = gLocalTime.minutes;
    gSpecialVar_0x8002 = gLocalTime.seconds;
    gSpecialVar_0x8003 = GetCurrentTimeOfDay();
    return FALSE;
    }
    There are high probability that I forgot something along the way.
    The first code is too long for me to put it here.

    Thanks if you take a look at it
     
  • 461
    Posts
    6
    Years
    • Seen yesterday
    You are right, I should have put the code here, just in case.

    So here is a part of a code in my file dns.c located in the src repo



    Here is the code of the dns.h file located in the include repo

    And here is the code of the dns.h file located in the include/constants repo

    I also add this in the scrcmd file

    There are high probability that I forgot something along the way.
    The first code is too long for me to put it here.

    Thanks if you take a look at it
    By script I meant the event script and not code, since the error in your first post says that the problem is in a script file.
    I can see that you have defined TIME_NIGHT, but it could still be the issue if you didn't include your new header file in data/event_scripts.s.
     
  • 17
    Posts
    333
    Days
    • Seen May 25, 2024
    I can see that you have defined TIME_NIGHT, but it could still be the issue if you didn't include your new header file in data/event_scripts.s.
    Yeah that was it. I didn't include the header in the file you were mentioning !
    So yeah it work better now.

    Thanks a lot
     
    Back
    Top