How to Operator Overloading in verse?

I was Making Array Sort but if I create Score Variable, compiler send me this error

 CompareCustomPlayerScores(A : CustomPlayer, B : CustomPlayer)<computes>: int = 
        #ERROR-Need Fix it
        AScore:int = A.GetScore()
        BScore:int = B.GetScore()
        #ERROR-Need Fix it
        if(AScore < BScore) then -1
        else if(AScore > BScore) then 1
        else 0

Error message
“This invocation calls a function that has effects that are not allowed by its context: transacts
no_rollback”

so I guess

I can’t use return function is that right?

in this case I think using operator ovloading is solution

but I can’t find how to Operator Overloading in verse

plz help me

Why not do this

        CompareCustomPlayerScores<public>(A : int, B : int)<transacts>: int = 
            if(A < B) then -1
            else if(A > B) then 1
            else 0

Then you can just call

if(A := CustomPlayer1.GetScore(), B := CustomPlayer2.GetScore()):
    CopareCustomPlayerScores(A, B)

I am not sure if this is the solution you’re looking for but this is how I used Array Sort in my game and it works.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.