Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Creating a specific array...

I need to create an array of 99 elements, each element being a struct i create earlier. Let me show you how I have tried this thus far.

struct invenvars
{
char name[64], description[64];
int value1, value2;
}

invenvars item;

declare inventory = new array[99];

//I setup the inventory variables here
...
//End setup

for(int loop = 1; loop < 100; loop++)
inventory[loop] = item;

Now everything seems OK, but it gives me a declaration error for 'inventory'. I am declaring it the way I am showed in my Borland Help files, but once again, they seem to be WRONG (big surprise, NOT). Can somebody show me how to declare an array properly in Win32? Thanks in advance.

-Seph


Comments

  • [code]typedef struct{
    char name[64];
    char description[64];
    int value1;
    int value2;
    }INVENVARS;

    INVENVARS invenvars[99];

    for(int loop = 1; loop < 100; loop++)
    {
    invenvars[loop].value1 = item;
    invenvars[loop].value2 = other_item;
    }

    invenvars[1].name = {'S','e','p','h','i','r','o','t','h'};
    [/code]

    Maybe this'll help.



  • [code]invenvars[1].name = {'S','e','p','h','i','r','o','t','h'};
    [/code]

    Should have been

    [code]invenvars[1].name[64] = "Sephiroth";[/code]



  • I need to have each location hold 4 values though. Something like:

    Inventory[1] = "Small Potion", "Restores 25 health", 1, 25;

    See I need to store the item name, descripption, total owned, and specific value in one slot. Is it possible to do this somehow? When I query Inventory[1] I need it to return those values into the item structure. I will then paste the item structure into the item window for the user to see.

    -Seph


  • I see what you mean now. That works PERFECTLY! I didn't understand how you were setting it up originally, but I see now.

    inventoryitem item[99];

    sprintf(item[1].name, "Potion");
    item[1].modifier = 25;

    This is excellent! Now there's no need for an array holding 99 of those structs, haha. Thanks man, you've been a BIG help!

    -Seph


  • Christinme7890Christinme7890 Posts: 6Member
    : I need to create an array of 99 elements, each element being a struct i create earlier. Let me show you how I have tried this thus far.
    :
    : struct invenvars
    : {
    : char name[64], description[64];
    : int value1, value2;
    : }
    :
    : invenvars item;
    :
    : declare inventory = new array[99];
    :
    : //I setup the inventory variables here
    : ...
    : //End setup
    :
    : for(int loop = 1; loop < 100; loop++)
    : inventory[loop] = item;
    :
    : Now everything seems OK, but it gives me a declaration error for 'inventory'. I am declaring it the way I am showed in my Borland Help files, but once again, they seem to be WRONG (big surprise, NOT). Can somebody show me how to declare an array properly in Win32? Thanks in advance.
    :
    : -Seph
    :
    :

    loop should start out at "0" because the array has 0 to 98 elements. It should end with "< 99". the way you had it it would start with 1 and end up with 99. There is no 99 array spot.
    for(int loop = 0; loop < 99; loop++)
    inventory[loop] = item;
    in declaring an array use the old c style:

    : typedef struct invenvars_
    : {
    : char name[64], description[64];
    : int value1, value2;
    : }invenvars;
    :
    : invenvars item[99];
    :
    : //I setup the inventory variables here
    : ...
    : //End setup
    :
    : for(int loop = 0; loop < 99; loop++)
    : inventory[loop] = item;


  • SephirothSephiroth Fayetteville, NC, USAPosts: 1,035Member
    Yeah I figured that out several months ago. Right now I am trying to figure out how to capture mouse coordinates inside a child window for the level editor. The game engine itself has been done.



    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red]


Sign In or Register to comment.