function on_input(self, action_id, action)
if action_id == hash("Note1") and action.pressed then
factoryname = hash("#FireBall_factory")
msg.post("/SpellFactory#SpellFactory", "create", {position = go.get_position(), rotation = vmath.quat(0,0,0,0), factoryname, components = {vel = vmath.vector3(0,0,1)}})
end
end
here is the code in the receiver
function on_message(self, message_id, message, sender)
if message_id == hash("create") then
pprint(message.components)
print(message.factoryname)
makespell(message.factoryname, sender, message.rotation, message.components, message.position)
end
end
both message.factoryname and message.components are nil and I am setting them in the table I sent through the message.
First problem is that you declare factoryname as a global function. You should always use the local keyword when declaring variables (unless you really know what you are doing):
local factoryname = hash("#FireBall_factory")
Second problem is that the message you’re passing is a mixed table of key-value pairs and array indexed values. You have position = go.get_position(), rotation = vmath.quat(0,0,0,0) and components = {vel = vmath.vector3(0,0,1)}. All of these are key-value pairs in the message table but you don’t do the same for the factory name. You should do factoryname = factoryname:
Now, you might wonder what happened to the factoryname? On the receiving end you could do pprint(message) to see the contents. You will see that the factoryname is there, but it will have been assigned the key 1, since it is the only value assigned to the array part of the table. Read more about Lua tables here: Programming in Lua : 2.5
You could you please try renaming the message from “create” to maybe “create_spell”? I’m thinking that “create” is a message used internally by the engine.