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

Modifying IV inheritance and a syntax error I can't solve

  • 23
    Posts
    6
    Years
    • Seen Nov 28, 2023
    Hi all,
    I am trying to modify IV inheritance to include a Destiny Knot type of mechanism. I am modifying the file src/daycare.c, and I'm getting a syntax error at make. The thing is, I can see which line the error comes from, but I cannot understand what the syntax error is. I've tried looking up similar lines elsewhere from the decomp, but for some reason this won't work.

    Here is my code:
    Code:
    static void InheritIVs(struct Pokemon *egg, struct DayCare *daycare)
    {
        int n = INHERITED_IV_COUNT;
    
        u32 motherItem = GetBoxMonData(&daycare->mons[0].mon, MON_DATA_HELD_ITEM);
        u32 fatherItem = GetBoxMonData(&daycare->mons[1].mon, MON_DATA_HELD_ITEM);
    
        // the offending lines are this block
        if (motherItem == ITEM_POTION || fatherItem == ITEM_POTION)
        {
            n = 5;
        }
        if (motherItem == ITEM_POKE_BALL || fatherItem == ITEM_POKE_BALL)
        {
            n = 6;
        }
    
        u8 i;
        u8 selectedIvs[n];
        u8 availableIVs[NUM_STATS];
        u8 whichParents[n];
        u8 iv;
    
        // Initialize a list of IV indices.
        for (i = 0; i < NUM_STATS; i++)
        {
            availableIVs[i] = i;
        }
    
        // Select the 3 IVs that will be inherited.
        for (i = 0; i < n; i++)
        {
            // Randomly pick an IV from the available list and stop from being chosen again.
            selectedIvs[i] = availableIVs[Random() % (NUM_STATS - i)];
            RemoveIVIndexFromList(availableIVs, i);
        }
    
        // Determine which parent each of the selected IVs should inherit from.
        for (i = 0; i < n; i++)
        {
            whichParents[i] = Random() % DAYCARE_MON_COUNT;
        }
    
        // Set each of inherited IVs on the egg mon.
        for (i = 0; i < n; i++)
        {
            switch (selectedIvs[i])
            {
                case 0:
                    iv = GetBoxMonData(&daycare->mons[whichParents[i]].mon, MON_DATA_HP_IV);
                    SetMonData(egg, MON_DATA_HP_IV, &iv);
                    break;
                case 1:
                    iv = GetBoxMonData(&daycare->mons[whichParents[i]].mon, MON_DATA_ATK_IV);
                    SetMonData(egg, MON_DATA_ATK_IV, &iv);
                    break;
                case 2:
                    iv = GetBoxMonData(&daycare->mons[whichParents[i]].mon, MON_DATA_DEF_IV);
                    SetMonData(egg, MON_DATA_DEF_IV, &iv);
                    break;
                case 3:
                    iv = GetBoxMonData(&daycare->mons[whichParents[i]].mon, MON_DATA_SPEED_IV);
                    SetMonData(egg, MON_DATA_SPEED_IV, &iv);
                    break;
                case 4:
                    iv = GetBoxMonData(&daycare->mons[whichParents[i]].mon, MON_DATA_SPATK_IV);
                    SetMonData(egg, MON_DATA_SPATK_IV, &iv);
                    break;
                case 5:
                    iv = GetBoxMonData(&daycare->mons[whichParents[i]].mon, MON_DATA_SPDEF_IV);
                    SetMonData(egg, MON_DATA_SPDEF_IV, &iv);
                    break;
            }
        }
    }

    And here is the error I get at make:
    Code:
    $ make
    src/daycare.c: In function `InheritIVs':
    src/daycare.c:549: syntax error before `i'
    src/daycare.c:556: `i' undeclared (first use in this function)
    src/daycare.c:556: (Each undeclared identifier is reported only once
    src/daycare.c:556: for each function it appears in.)
    src/daycare.c:558: `availableIVs' undeclared (first use in this function)
    src/daycare.c:565: `selectedIvs' undeclared (first use in this function)
    src/daycare.c:572: `whichParents' undeclared (first use in this function)
    src/daycare.c:581: `iv' undeclared (first use in this function)
    agbcc: warnings being treated as errors
    src/daycare.c:582: warning: unreachable code at beginning of switch statement
    make: *** [Makefile:250: build/emerald/src/daycare.o] Virhe 1

    Line 549 is
    Code:
    u8 i;
    so something goes wrong when the items of the parents are checked. If I comment out those lines, everything works. So, my question is, what is the syntax error here? I'm sure it's something simple, but this is driving me nuts. I even checked that there are no mixed whitespaces.

    I would greatly appreciate any help! Thank you in advance for anyone who reads this.
     
  • 146
    Posts
    16
    Years
    • Age 26
    • Seen May 20, 2024
    I would greatly appreciate any help! Thank you in advance for anyone who reads this.
    You need to declare all of your variables at the top of the function. I'd also change int to u8 just to be consistent. So the top of your method should look like this:
    Code:
    static void InheritIVs(struct Pokemon *egg, struct DayCare *daycare)
    {
        u8 n = INHERITED_IV_COUNT;
        u8 i;
        u8 selectedIvs[n];
        u8 availableIVs[NUM_STATS];
        u8 whichParents[n];
        u8 iv;

    And if you're interested, takyon and I were working on porting all of the newer day-care mechanics over to pokeemerald (using DizzyEgg's engines).
    Here's the link to that thread.
    Hope this helps!
     
  • 23
    Posts
    6
    Years
    • Seen Nov 28, 2023
    And if you're interested, takyon and I were working on porting all of the newer day-care mechanics over to pokeemerald (using DizzyEgg's engines).
    Here's the link to that thread.
    Hope this helps!

    Thank you for the link, this is superb! I will definitely check this out. I hadn't discovered your work previously, so I'm thrilled that other people are interested in day care mechanisms as well!
     
    Back
    Top