# Math Conversion Problems

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

## Recommended Posts

I'm trying to use my own Vector class and am running into issues.

I have two functions in my Vector class that allow it to multiple with a float in any order like this.

friend Vector operator+ (const Vector& t, float f) {return Vector(t.x+f,t.y+f,t.z+f);}
friend Vector operator+ (float f, const Vector& t) {return Vector(t.x+f,t.y+f,t.z+f);}


I don't know how to register this with AngelScript so that I can multiple a Vector with a float in any order. I've tried registering it like this, but it gives an error that it failed to register the second function. I'm guessing because I've declared opMul already with the same declaration?

engine->RegisterObjectMethod("Vector", "Vector opMul(float f)", asFUNCTIONPR(operator*, (const Vector&, float), Vector), asCALL_CDECL_OBJFIRST);
engine->RegisterObjectMethod("Vector", "Vector opMul(float f)", asFUNCTIONPR(operator*, (float, const Vector&), Vector), asCALL_CDECL_OBJLAST);


If I comment out either line above, so I'm only registering one of the functions (doesn't matter which one), then it works in script in the order of Vector * float. But it fails if I try to do float * Vector. I get an error that says "No conversion from 'Vector' to math type available."

How can I set up my Vector class so I can multiply if by a float in any order, i.e. Vector * float or float * Vector?

##### Share on other sites

Oh wow, thank you! I even read that page before posting, but just didn't pick up on that point. This has solved the problem.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 10
• 9
• 37
• 16
• ### Forum Statistics

• Total Topics
634125
• Total Posts
3015683
×