Jump to content
  • Advertisement
Sign in to follow this  
Psych0 P3ngu1n

Question on code

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

int main() { Ogre bill; Ogre ted; Spell fireball; Spell thunderbolt; Spell freezeray; Spell spells[] = { fireball, thunderbolt, freezeray }; Spell &spell = spells[rand() % 3]; bill.SpellUse(spell); ted.SpellUse(spell); } here is code that Rip-Off gave me a few days ago to help with a lab for class, for my own knowledge however, i wanted to know if there was a way to show what spell was being used when the application was ran. If so, can you please show me the code for it. Thanks for taking time to read my thread. (and reply if you do.)

Share this post


Link to post
Share on other sites
Advertisement
When you create the spells give them a string so that they know which spell they are. Then after you assign to spell print out the string you gave it previously.

Something like
Spell fireball("fireball");
then
std::cout << spell << std::endl;

Share this post


Link to post
Share on other sites
you could compare the memory addresses as this is really the only property in which those objects differ.

int main()
{
Ogre bill;
Ogre ted;
Spell fireball;
Spell thunderbolt;
Spell freezeray;

Spell spells[] = { fireball, thunderbolt, freezeray };
Spell &spell = spells[rand() % 3];

if (&spell == &fireball) {
cout << "Yay! Fireball!";
}

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!