Skip to main content

User login

What is OpenID?
  • Log in using OpenID
  • Cancel OpenID login
  • Create new account
  • Request new password
Register
  • Home
  • Browse
    • 2D Art
    • 3D Art
    • Concept Art
    • Textures
    • Music
    • Sound Effects
    • Documents
    • Featured Tutorials
  • Submit Art
  • Collect
    • My Collections
    • Art Collections
  • Forums
  • FAQ
  • Leaderboards
    • All Time
      • Total Points
      • Comments
      • Favorites (All)
      • Favorites (2D)
      • Favorites (3D)
      • Favorites (Concept Art)
      • Favorites (Music)
      • Favorites (Sound)
      • Favorites (Textures)
    • Weekly
      • Total Points
      • Comments
      • Favorites (All)
      • Favorites (2D)
      • Favorites (3D)
      • Favorites (Concept Art)
      • Favorites (Music)
      • Favorites (Sound)
      • Favorites (Textures)
  • ❤ Donate
Programming

World Amount Objects - Sry my english is bad :c

TobiPL
Thursday, June 1, 2017 - 07:04

Hello I'm Tobi and how u can see im from Poland ^_^ -> TobiPL ( PL -> Poland :D )

thats why my English is bad ;c... Sorry...

 

i wanna make my Code Better but idk How... Look:

 

<code>

struct WorldObject

{

    int posx,

        posy;

    short type;

};

struct World{WorldObject Object[50];};

World Test[3][3];

</code>

 

How u can see i have Struct named "WorldObject" and Every object have PosX , posY and Type ( ID to Graphics )

and i have another Struct names "World" and inside this Struct i have 50 Objetsc from struct "WorldObject"

 

and now my Problem... how can i set different Amount of "WorldObject" in evey "cell" in "world" 

something like:

World Test[1][1] have 30 World Objects

World Test[1][2] have 100 World Objects

World Test[1][3] have 50 World Objects..

 

i was trying with something like this:

<code>

Struct World

{

int Amount;

WorldObjects[Amount];

}

</code>

 

but i got Error ;/...

  • Log in or register to post comments
marko
joined 14 years 3 months ago
Friday, June 2, 2017 - 02:17

(Assuming this is C or C++.) You can only declare arrays to be of a fixed (const) length. Also the syntax of that declaration isn't right anyway.

 

So for example you could declare: const int max_amount_c = 50; if you knew that was the largest a world cell could be. And then it would be: WorldObject WorldObjects[max_amount_c];

 

More generally you need to dynamically allocate an array and use a pointer, to allow arrays of arbitrary length.

 

If you're using C++, I'd recommend using something like the vector class.

  • Log in or register to post comments