Jump to content
  • Advertisement
Sign in to follow this  
jblevins1991

question about storing objects in arrays.

This topic is 2252 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

here is my attack class

attack class
{

int power;

int init(void)
{
opponenthp=-power;
}
};

if i store attack.init() in an array whenever i select the unit that stores attack.init() would run that function correct? if there are any suprises or things that you may want me to know about the way im doing this feel free to tell me :).

thank you for anybody who helps ive only been programming for 6 months.

Share this post


Link to post
Share on other sites
Advertisement
mm.. okay
I see a few bugs here, so you'll probably need to rewrite this :)
1) you need to have a pointer to the opponent / opponentHP, to say opponentHP -= attack; so, try and use pointers / references
2) you're not actually initialising "power" in your attack class. So you need to use a constructor for that.
3) you can't store attack.Init(). You can just store an array of attack objects. something like <code> attack myAttacks[10]; </code>
4) you probably don't want to do <code>opponentHP = -power</code>; rather, you want to say <code>opponentHP = opponentHP - power; OR opponentHP -= power; </code>

hope this helps

Share this post


Link to post
Share on other sites

here is my attack class

attack class
{
int power;

int init(void)
{
opponenthp=-power;
}
};
...


sorry i thought i had, it's c++.

No it isn't. For a start, it's [font=courier new,courier,monospace]class attack[/font]. I suggest to use [font=courier new,courier,monospace]class Attack[/font] instead; it appears that tools such as Doxygen silently assume classes begin by uppercase characters. Are you sure you want to have an init call? Why not to use it in the ctor? Or, for a better question, why is this function called [font=courier new,courier,monospace]init() [/font]instead of [font=courier new,courier,monospace]DealSomeDamage()[/font]?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!