Jump to content
  • Advertisement
Sign in to follow this  
STufaro

Comparing types.

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

Hey guys - I'm in VB6 (but everything should be just about the same [except for some minor syntax] with other languages). I'd like to compare two things that are types (specifically two D3DMATERIAL8s) in an If-Then statement to prevent unneccessarily replicating them within my game engine. So I have: If Material1 = Material2 Then... But when I go to run it, VB highlights the = sign and says "Type: mismatch", even though the are of the same type, D3DMATERIAL8. I AM, however, allowed to copy Material1 to Material2 like Material2 = Material1 I tried using "Is" as well to no avail. So I assume this is a problem that exists beyond just the Material types. I guess you can't compare ANY types then without comparing their individual elements separately? The D3DMATERIAL8 types are composed of D3DCOLORVALUE types, which themselves are composed of Singles. Maybe I can't compare the types because the types themselves are made up of other types? So, bottom line: Is there a way I can compare types without comparing each of their individual elements? Why isn't this working and why am I getting a mismatch? Thanks! Much obliged, - Steve.

Share this post


Link to post
Share on other sites
Advertisement
Are you actually comparing the 2 objects like this:

if (Material1=Material2) {
//stuff
}


I'm not familiar with VB6, but, in C style languages a comparison is 2 = together, so that becomes

if (Material1==Material2) {
//stuff
}

A single = assigns the right to the left, so Material1 is becoming a copy of Material2. Oddly enough, this usually returns the variable being copied, so that statement can be used in an expression. In this case that's a material object. Because the compiler sees an if statement, and wants a boolean expression to go along with it, it's confused by the fact that you are putting a material there. That's why you can assign, but not compare, because you are still assigning!

Short version:
Try using == instead of =.

Share this post


Link to post
Share on other sites
Thanks for the reply!

I should have mentioned that the = and == are the same in VB6; not so with C languages.

The problem is that VB does not have any built-in way of comparing types, you either have to compare them element by element or use something described in this thread I started:

http://www.xtremevbtalk.com/showthread.php?t=298327

which basically provides a way to port the memcmp function to VB by substituting an API call.

Thanks again, though.

- Steve.

Share this post


Link to post
Share on other sites
I too don't know much about VB6 (although i did know that it doesn't use ==), but does the equality operator compare pointers like C/C++ or does it actually compare them element by element, which you seemed to say it didn't. All else failing, you could just write a function that compared each element.

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!