Windows programming

Moderators: None (Apply to moderate this forum)
Number of threads: 3711
Number of posts: 9173

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Edit Report
Creating a specific array... Posted by Sephiroth on 15 Jan 2001 at 9:29 PM
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


Edit Report
Re: Creating a specific array... Posted by Hey Joe on 15 Jan 2001 at 11:27 PM
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'};


Maybe this'll help.



Edit Report
Doh!! Posted by Hey Joe on 16 Jan 2001 at 12:08 AM
invenvars[1].name = {'S','e','p','h','i','r','o','t','h'};


Should have been

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




Edit Report
Re: Doh!! Posted by Sephiroth on 16 Jan 2001 at 10:12 AM
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


Edit Report
My head wasn't on right, Joe... Posted by Sephiroth on 16 Jan 2001 at 10:24 AM
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


Report
Re: Creating a specific array... Posted by Christinme7890 on 9 Apr 2001 at 2:55 PM
: 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;


Report
Re: Creating a specific array... Posted by Sephiroth on 10 Apr 2001 at 10:00 AM
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.



-Sephiroth





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.