Message posting variables

This is the code for making my enemy shoot an I’m getting it to send a message to the game objects it spawns which works but I cant get it to sent the player_pos which i have set earlier it this code which is the location of my player game object. I have checked and player_pos does have a value before it is being sent by the msg.post

		local factID = factory.create("#bullet_factory", go.get_position())
		print(factID)
		msg.post(factID, "player_pos", { player_pos })

This is the code which is in the game object that is being spawned by the factory:

function on_message(self, message_id, message, sender)
	if message_id == hash("player_pos") then
		print("hello")
		print(player_pos)
	end
end

at the moment player_pos is printing nil.
Any help would be much appreciated,
Thanks,
Tom

I might be wrong but I think you need to send it as { player_pos = } in the table

5 Likes

And this:

print(player_pos)

Needs to be:

print(message.player_pos)
5 Likes

Thanks a lot, sorry for the late reply but that fixed it!!!

Thanks so much, that’s fixed it