How does the "mesasge" in msg.post work

I’m trying to send a msg

msg.post("/m_char#m_char_script", "set_pos", vmath.vector3(0, 0, 0))

to another script to set its position to I’m trying to send the position as a vector3 but when I do I get this error

ERROR:SCRIPT: bad argument #3 to 'post' (table expected, got userdata)

but if I make it a table it doesn’t work in the other script because it isn’t a vector3 and it gives me this error. What can I do

ERROR:SCRIPT: bad argument #1 to 'set_position' (vector3 expected, got table)

Any ideas why. Thanks

You receive a table.
Use e.g. ”message.myposition”

Have you read the manual on messages?

1 Like

Thanks. I’ve used

table.remove(message)

and it works now.

The error for this line states clearly that it expects a table at 3. argument, but you are passing a vector here (type of vector is “userdata”)

You can simply put your vector inside a table and pass it:

    msg.post("/m_char#m_char_script", "set_pos", { position = vmath.vector3(0, 0, 0) } )
1 Like

We don’t know where you put it, but I suspect in the receiver’s on_message code - because on_message has a message parameter. I don’t know how it resolved your issue though :grin:

Check out my above post for a correct solution :wink:

1 Like

I forgot to mention I made it a table like how you said too and you’re right

table.remove(message)

is in the recevers on_message. Thanks

1 Like