OPSPESH
September 22, 2024, 11:03am
1
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”
britzl
September 22, 2024, 12:46pm
3
OPSPESH:
Any ideas why. Thanks
Have you read the manual on messages?
1 Like
Pawel
September 22, 2024, 11:13pm
5
OPSPESH:
msg.post("/m_char#m_char_script", "set_pos", vmath.vector3(0, 0, 0))
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
Pawel
September 22, 2024, 11:16pm
6
OPSPESH:
Thanks. I’ve used
table.remove(message)
and it works now.
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
Check out my above post for a correct solution
1 Like
OPSPESH
September 23, 2024, 9:39am
7
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