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

Help with adding an item function

124
Posts
8
Years
    • Seen Apr 5, 2024
    I need help adding an item function to an ItemUseOutOfBattle_ function.

    I did all the adding of the item and its description but not sure how to make it work

    I want the item to simply let me use the the special called:
    special(ShowPokemonStorageSystemPC)

    and I want to register it and use it whenever, any help on how I should set up the function would be great. Thanks
     
    453
    Posts
    6
    Years
    • Seen May 17, 2024
    I need help adding an item function to an ItemUseOutOfBattle_ function.

    I did all the adding of the item and its description but not sure how to make it work

    I want the item to simply let me use the the special called:
    special(ShowPokemonStorageSystemPC)

    and I want to register it and use it whenever, any help on how I should set up the function would be great. Thanks
    You can use the special by calling its corresponding C function.
    Look at existing ItemUseOutOfBattle functions in src/item_use.c to see how they work and use that as the basis for your custom function.
     
    124
    Posts
    8
    Years
    • Seen Apr 5, 2024
    this is the function I came up with with the info you provided

    void ItemUseOutOfBattle_MiniPc(void)
    {
    u8 taskId = CreateTask(Task_PCMainMenu, 80);
    gTasks[taskId].tState = 0;
    gTasks[taskId].tSelectedOption = 0;
    LockPlayerFieldControls();
    }

    these are the errors Im getting

    src/data/items.h:9661: warning: initialization from incompatible pointer type
    src/data/items.h:9662: `MINI_PC' undeclared here (not in a function)
    src/data/items.h:9662: initializer element for `gItems[799].secondaryId' is not constant
    src/data/items.h:9663: initializer element for `gItems[799]' is not constant
    src/item_use.c: In function `ItemUseOutOfBattle_MiniPc':
    src/item_use.c:109: `Task_PCMainMenu' undeclared (first use in this function)
    src/item_use.c:109: tools/agbcc/bin/agbcc <flags> -o build/emerald/src/lilycove_lady.o src/lilycove_lady.c
    (Each undeclared identifier is reported only once
    src/item_use.c:109: for each function it appears in.)
    src/item_use.c:110: structure has no member named `tState'
    src/item_use.c:111: structure has no member named `tSelectedOption'
    tools/agbcc/bin/agbcc <flags> -o build/emerald/src/link.o src/link.c
    tools/agbcc/bin/agbcc <flags> -o build/emerald/src/link_rfu_2.o src/link_rfu_2.c
    tools/agbcc/bin/agbcc <flags> -o build/emerald/src/link_rfu_3.o src/link_rfu_3.c
    tools/agbcc/bin/agbcc <flags> -o build/emerald/src/list_menu.o src/list_menu.c
    make: *** [Makefile:391: build/emerald/src/item.o] Error 1
    make: *** Deleting file 'build/emerald/src/item.o'
    make: *** Waiting for unfinished jobs....
    make: *** [Makefile:391: build/emerald/src/item_use.o] Error 1
    make: *** Deleting file 'build/emerald/src/item_use.o'

    Any idea what its talking bout?
     

    Lunos

    Random Uruguayan User
    3,115
    Posts
    15
    Years
  • this is the function I came up with with the info you provided

    void ItemUseOutOfBattle_MiniPc(void)
    {
    u8 taskId = CreateTask(Task_PCMainMenu, 80);
    gTasks[taskId].tState = 0;
    gTasks[taskId].tSelectedOption = 0;
    LockPlayerFieldControls();
    }

    these are the errors Im getting

    src/data/items.h:9661: warning: initialization from incompatible pointer type
    src/data/items.h:9662: `MINI_PC' undeclared here (not in a function)
    src/data/items.h:9662: initializer element for `gItems[799].secondaryId' is not constant
    src/data/items.h:9663: initializer element for `gItems[799]' is not constant
    src/item_use.c: In function `ItemUseOutOfBattle_MiniPc':
    src/item_use.c:109: `Task_PCMainMenu' undeclared (first use in this function)
    src/item_use.c:109: tools/agbcc/bin/agbcc <flags> -o build/emerald/src/lilycove_lady.o src/lilycove_lady.c
    (Each undeclared identifier is reported only once
    src/item_use.c:109: for each function it appears in.)
    src/item_use.c:110: structure has no member named `tState'
    src/item_use.c:111: structure has no member named `tSelectedOption'
    tools/agbcc/bin/agbcc <flags> -o build/emerald/src/link.o src/link.c
    tools/agbcc/bin/agbcc <flags> -o build/emerald/src/link_rfu_2.o src/link_rfu_2.c
    tools/agbcc/bin/agbcc <flags> -o build/emerald/src/link_rfu_3.o src/link_rfu_3.c
    tools/agbcc/bin/agbcc <flags> -o build/emerald/src/list_menu.o src/list_menu.c
    make: *** [Makefile:391: build/emerald/src/item.o] Error 1
    make: *** Deleting file 'build/emerald/src/item.o'
    make: *** Waiting for unfinished jobs....
    make: *** [Makefile:391: build/emerald/src/item_use.o] Error 1
    make: *** Deleting file 'build/emerald/src/item_use.o'

    Any idea what its talking bout?
    Errors related to an item whose data you added to src/data/items.h which we cannot really help you with because you didn't share anything to analyze.
    src/item_use.c:109: `Task_PCMainMenu' undeclared (first use in this function)
    You're trying to call a function called Task_PCMainMenu without having declared it, either near the top of the file with the rest of the static functions if it's a static function, or in some .h file at include/ if it's meant to be a global function.
    src/item_use.c:110: structure has no member named `tState'
    src/item_use.c:111: structure has no member named `tSelectedOption'
    You're trying to use struct variables that are not defined anywhere inside of a function.
    I don't know if they're related to the ItemUseOutOfBattle_MiniPc you posted or not, but those are some very early file line numbers.

    Considering how you already left out code you added to src/data/items.h from your post, I'd be inclined to believe that this ItemUseOutOfBattle_MiniPc isn't the only function or change in the codebase that you made.
    Can you please post a code diff?
    You can get one using git diff, and you can optionally export it into a text file using git diff > file.txt.
     
    124
    Posts
    8
    Years
    • Seen Apr 5, 2024
    Errors related to an item whose data you added to src/data/items.h which we cannot really help you with because you didn't share anything to analyze.

    You're trying to call a function called Task_PCMainMenu without having declared it, either near the top of the file with the rest of the static functions if it's a static function, or in some .h file at include/ if it's meant to be a global function.

    You're trying to use struct variables that are not defined anywhere inside of a function.
    I don't know if they're related to the ItemUseOutOfBattle_MiniPc you posted or not, but those are some very early file line numbers.

    Considering how you already left out code you added to src/data/items.h from your post, I'd be inclined to believe that this ItemUseOutOfBattle_MiniPc isn't the only function or change in the codebase that you made.
    Can you please post a code diff?
    You can get one using git diff, and you can optionally export it into a text file using git diff > file.txt.
    you are right lunos, i havent been very clear of what i've done, and if anybody can help, im sure you can...i have posted all my changes below. Please help me figure this out. I just want the item to let me use the storage system, not the whole pc.
    ---------------------------
    ----------------------------------------------------
    ....in include/constants/items.h

    #define ITEM_BERSERK_GENE 798
    #define ITEM_MINI_PC 799

    #define ITEMS_COUNT 800
    -----------------------------------------------------
    ....in src/data/item_icon_table.h

    [ITEM_BERSERK_GENE] = {gItemIcon_BerserkGene, gItemIconPalette_BerserkGene},
    [ITEM_MINI_PC] = {gItemIcon_ExpShare, gItemIconPalette_ExpShare},
    [ITEMS_COUNT] = {gItemIcon_ReturnToFieldArrow, gItemIconPalette_ReturnToFieldArrow},
    -----------------------------------------------------
    ....in src/data/items.h

    [ITEM_MINI_PC] =
    {
    .name = _("Mini-PC"),
    .price = 0,
    .description = sMiniPcDesc,
    .importance = 1,
    .pocket = POCKET_KEY_ITEMS,
    .type = ITEM_USE_FIELD,
    .fieldUseFunc = ItemUseOutOfBattle_MiniPc,
    },
    -----------------------------------------------------
    .....in src/data/item_descriptions.h

    static const u8 sMiniPcDesc[] = _(
    "Allows storage\n"
    "of your Pokémon\n"
    "wirelessly.");
    -------------------------------------------------------
    ....in include/item_use.h

    void ItemUseOutOfBattle_MiniPc(void);

    ------------------------------------------------------
    ....in src/item_use.c

    void ItemUseOutOfBattle_MiniPc(void)
    {
    u8 taskId = CreateTask(Task_PCMainMenu, 80);
    gTasks[taskId].tState = 0;
    gTasks[taskId].tSelectedOption = 0;
    LockPlayerFieldControls();
    }
     
    Last edited:

    Lunos

    Random Uruguayan User
    3,115
    Posts
    15
    Years
  • S
    you are right lunos, i havent been very clear of what i've done, and if anybody can help, im sure you can...i have posted all my changes below. Please help me figure this out. I just want the item to let me use the storage system, not the whole pc.
    ---------------------------
    ----------------------------------------------------
    ....in include/constants/items.h

    #define ITEM_BERSERK_GENE 798
    #define ITEM_MINI_PC 799

    #define ITEMS_COUNT 800
    -----------------------------------------------------
    ....in src/data/item_icon_table.h

    [ITEM_BERSERK_GENE] = {gItemIcon_BerserkGene, gItemIconPalette_BerserkGene},
    [ITEM_MINI_PC] = {gItemIcon_ExpShare, gItemIconPalette_ExpShare},
    [ITEMS_COUNT] = {gItemIcon_ReturnToFieldArrow, gItemIconPalette_ReturnToFieldArrow},
    -----------------------------------------------------
    ....in src/data/items.h

    [ITEM_MINI_PC] =
    {
    .name = _("Mini-PC"),
    .price = 0,
    .description = sMiniPcDesc,
    .importance = 1,
    .pocket = POCKET_KEY_ITEMS,
    .type = ITEM_USE_FIELD,
    .fieldUseFunc = ItemUseOutOfBattle_MiniPc,
    },
    -----------------------------------------------------
    .....in src/data/item_descriptions.h

    static const u8 sMiniPcDesc[] = _(
    "Allows storage\n"
    "of your Pokémon\n"
    "wirelessly.");
    -------------------------------------------------------
    ....in include/item_use.h

    void ItemUseOutOfBattle_MiniPc(void);

    ------------------------------------------------------
    ....in src/item_use.c

    void ItemUseOutOfBattle_MiniPc(void)
    {
    u8 taskId = CreateTask(Task_PCMainMenu, 80);
    gTasks[taskId].tState = 0;
    gTasks[taskId].tSelectedOption = 0;
    LockPlayerFieldControls();
    }
    So, there's a handful of problems here.

    Firstly, you're trying to start a task machine by executing the function Task_PCMainMenu via CreateTask.
    The problem with doing this is that Task_PCMainMenu is a static function located in src/pokemon_storage_system.c by default.
    Due to its static scope, no file in the project outside of the one it's in (src/pokemon_storage_system.c) can make use of it.
    You want to change the function's scope from static to global, which is done by removing its static prefix, then defining the function in some header file (in this case the obvious choice being include/pokemon_storage_system.h because that's the header file in which the global functions and arrays from src/pokemon_storage_system.c are declared), and then making sure that that header file is #included in src/item_use.c, the file in which you're trying to use the function.

    Secondly, and this is the more obvious issue; you're trying to use labels such as "tState" and "tSelectedOption", and because you didn't post an actual git diff like I asked you to, I can't really tell if you have those defined anywhere in the file or not, but I'm inclined to think that they're not given the errors I quoted in my previous post and given the fact that there are no variables with such labels defined in src/item_use.c by default.
    Those labels are normally assigned to the data parameters of a task function, and are used to make the code more readable and easier to understand.
    Since you're not trying to use raw "data[X]" arguments, you need to define these labels manually before your ItemUseOutOfBattle_MiniPc function, and since the codebase uses variables with the same sort of labels in many other files, you'll want to #undef them after you're done using them.
    Now, the thing here is that you're initializing them to 0, which is their default value (task data variables default to 0). As a result, the better solution is to just skip them entirely.

    Thirdly, the function assigned for an item's OutOfBattle has to be a function that reads a parameter.
    This can be seen in every single function whose label contains ItemUseOutOfBattle.
    You can't just pass a function that reads no parameters and expect things to work because of how the code is laid out.

    I'd say the easier way to go about this is to add a new script to data/scripts/pc.inc if you don't like any of the ones that are there by default, and then execute that through your item via ScriptContext_SetupScript, like berries or the Wailmer Pail do, but I focused on making your code work by reading how other functions inside src/item_use.c are written.
    Here's an actual code diff:
    Spoiler:


    The only issue I could spot is that for whatever reason the textbox that is spawned by Task_PCMainMenu isn't cleared when pressing B.
    I'll leave fixing that up to you.
    Help with adding an item function
    Help with adding an item function
     
    124
    Posts
    8
    Years
    • Seen Apr 5, 2024
    S
    So, there's a handful of problems here.

    Firstly, you're trying to start a task machine by executing the function Task_PCMainMenu via CreateTask.
    The problem with doing this is that Task_PCMainMenu is a static function located in src/pokemon_storage_system.c by default.
    Due to its static scope, no file in the project outside of the one it's in (src/pokemon_storage_system.c) can make use of it.
    You want to change the function's scope from static to global, which is done by removing its static prefix, then defining the function in some header file (in this case the obvious choice being include/pokemon_storage_system.h because that's the header file in which the global functions and arrays from src/pokemon_storage_system.c are declared), and then making sure that that header file is #included in src/item_use.c, the file in which you're trying to use the function.

    Secondly, and this is the more obvious issue; you're trying to use labels such as "tState" and "tSelectedOption", and because you didn't post an actual git diff like I asked you to, I can't really tell if you have those defined anywhere in the file or not, but I'm inclined to think that they're not given the errors I quoted in my previous post and given the fact that there are no variables with such labels defined in src/item_use.c by default.
    Those labels are normally assigned to the data parameters of a task function, and are used to make the code more readable and easier to understand.
    Since you're not trying to use raw "data[X]" arguments, you need to define these labels manually before your ItemUseOutOfBattle_MiniPc function, and since the codebase uses variables with the same sort of labels in many other files, you'll want to #undef them after you're done using them.
    Now, the thing here is that you're initializing them to 0, which is their default value (task data variables default to 0). As a result, the better solution is to just skip them entirely.

    Thirdly, the function assigned for an item's OutOfBattle has to be a function that reads a parameter.
    This can be seen in every single function whose label contains ItemUseOutOfBattle.
    You can't just pass a function that reads no parameters and expect things to work because of how the code is laid out.

    I'd say the easier way to go about this is to add a new script to data/scripts/pc.inc if you don't like any of the ones that are there by default, and then execute that through your item via ScriptContext_SetupScript, like berries or the Wailmer Pail do, but I focused on making your code work by reading how other functions inside src/item_use.c are written.
    Here's an actual code diff:
    Spoiler:


    The only issue I could spot is that for whatever reason the textbox that is spawned by Task_PCMainMenu isn't cleared when pressing B.
    I'll leave fixing that up to you.
    Help with adding an item function
    Help with adding an item function
    that looks great lunos, unfortunately Im sorry I cant get it to work, did all your changes and got these errors when compiling:

    src/item_use.c: In function `ItemUseOutOfBattle_MiniPc':
    src/item_use.c:119: warning: implicit declaration of function `SetUpItemUseOnFieldCallback'
    src/item_use.c: At top level:
    src/item_use.c:157: warning: type mismatch with previous implicit declaration
    src/item_use.c:119: warning: previous implicit declaration of `SetUpItemUseOnFieldCallback'
    src/item_use.c:157: warning: `SetUpItemUseOnFieldCallback' was previously implicitly declared to return `int'

    I wish I knew how to git diff and be more descriptive to you so it be easier to help me.
     

    Lunos

    Random Uruguayan User
    3,115
    Posts
    15
    Years
  • that looks great lunos, unfortunately Im sorry I cant get it to work, did all your changes and got these errors when compiling:

    src/item_use.c: In function `ItemUseOutOfBattle_MiniPc':
    src/item_use.c:119: warning: implicit declaration of function `SetUpItemUseOnFieldCallback'
    src/item_use.c: At top level:
    src/item_use.c:157: warning: type mismatch with previous implicit declaration
    src/item_use.c:119: warning: previous implicit declaration of `SetUpItemUseOnFieldCallback'
    src/item_use.c:157: warning: `SetUpItemUseOnFieldCallback' was previously implicitly declared to return `int'
    SetUpItemUseOnFieldCallback is a static function present in src/item_use.c located towards the upper part of the file.
    You need to add the ItemUseOutOfBattle_MiniPc function somewhere below it because the function (SetUpItemUseOnFieldCallback) isn't declared near the top of the file alongside the rest of static functions for w/e reason.
    I wish I knew how to git diff
    I already told you how to use it above.
     
    124
    Posts
    8
    Years
    • Seen Apr 5, 2024
    SetUpItemUseOnFieldCallback is a static function present in src/item_use.c located towards the upper part of the file.
    You need to add the ItemUseOutOfBattle_MiniPc function somewhere below it because the function (SetUpItemUseOnFieldCallback) isn't declared near the top of the file alongside the rest of static functions for w/e reason.

    I already told you how to use it above.
    I got it to work thanks for letting me kno I had to put those functions close to the bottom. Now i got to just figure out how to clear the message box after I leave the menu. Not sure what to write or where to put it.
     
    Last edited:
    Back
    Top