So I think I did everything right, but somehow it is not working.
In the basic_ai.script which belongs to gameobject ai_character I call this line:
msg.post("level_controller#script", "get_new_target", {my_id = go.get_id()})
So the message should go to the gameobject level_controller and from there to the script. This script also created all ai_characters in my game. The on_message function looks like this:
local get_new_target_hash = hash("get_new_target")
function on_message(self, message_id, message, sender)
if message_id == get_new_target_hash then
local new_target = get_new_target(self, message.my_id)
msg.post(sender, "new_target", {target = new_target})
end
end
So the ai_character asks the level_controller for a new target (another ai_character he can go to). Now the level_controller should send a message with the new target back to the ai_character, but that somehow doesn’t work.
on_message of basic_ai.script:
function on_message(self, message_id, message, sender)
if message_id == new_target_hash then
if self.state == looking_for_opponent then
self.state = moving
self.target = message.target
end
end
end
The ai_character never reaches the state moving. I’m already trying the whole day to find out what I’m doing wrong, but got no further. Am I missing something?
My Level Collection:
Another Question: When I create a gameobject with factory.create() an id will be returned. Is this the same id as the one that I will get, when i call go.get_id() in a script in the created gameobject?