Error with math.abs() - "Number expected, got userdata"

I’ve set up a variable:

self.velocity = vmath.vector3()

I’m attempting to use the absolute value of its x-value:

math.abs(self.velocity.x)

However, this returns the error "Bad argument #1 to ‘abs’ (number expected, got userdata). This happens even when I initialize each of the values to any number:

self.velocity = vmath.vector3(1, 1, 1)

I would appreciate some help on what is causing this!

Strange. Here this works and prints 2:

self.velocity = vmath.vector3(2, 3, 4)
print(math.abs(self.velocity.x))

Can you share a full script with the code that you are running. Perhaps something is altering self.velocity somehow?

1 Like