Jump to content
  • Advertisement
Sign in to follow this  
I Am Legend

Giving objects in arrays properties

This topic is 3697 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm making a menu that has an array of Menu Items. I'm wondering how I can change the properties of the objects in the array, each object has 3 things to change if it make a difference

Share this post


Link to post
Share on other sites
Advertisement
What programming language? "Property" sounds like you're referring to C# or Obj-c, or do you mean "property" in the generic sense?

Share this post


Link to post
Share on other sites
A Win32 menu or what? I have never dealt with any time of menu, so I'm probabaly clueless. If it's a custom menu you wrote, I guess make a class called MenuItem and in it, have the public variables things like int width; int height; string text, and other properties you want. Then make an array of MenuItem so when you add something to that array, also set the properties of it you want. I could be completely off and not help at all, but w/e lol.

Share this post


Link to post
Share on other sites
I'm used to C++, but does C# have #include <vector>? if so, just to vector<MenuItem*> menuItems; to make an array of menuitem pointers. Then to add to it, just do MenuItem* newItem; newItem->property = "whatever"; menuItems.push_back(newItem);

[Edited by - Tenac on July 2, 2008 4:32:25 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by I Am Legend
What you said is exactly what I'm trying to do, but I don't know how to give the objects the values


You specify the object whose value you want to set, in the normal way that you specify an element of an array, and then set its property in the normal way.


myArray[0].foo = 42
^ ^^^^^^^ ^ ^^
| ||||||| + ++---------------------------------------+
| ||||+++-+-------------------------------------+ |
| |||+----+---------------------------------+ | |
| ||| +---------------------------+ | | |
| look at the 0th element | | | |
+------------------------- of myArray, and set its foo to 42.

Share this post


Link to post
Share on other sites
Do you simply mean something like this?


foreach (MenuItem menuItem in menuItemArray)
{
menuItem.Property1 = something;
menuItem.Property2 = somethingElse;
menuItem.Property3 = somethingElse;
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!