Phodex Games Posted September 13, 2016 Share Posted September 13, 2016 Hello, currently I am working on my AI system, but I have a problem setting up multiple NPCs. What you need to know: - My AI is able to randomly move around in the world using waypoints. - I coded an own animation manager "class" The Problem: I set one NPC to not move around and the other to do so. It works fine. One is moving, one is standing still, BUT the one moving is not playing an animation. So he is kind of floating around. The one who is standing is playing the walk animation. So I printed some values to find the error. By the way if I just have on NPC active everything works fine without any trouble. This is the code of my animation manager class: function AnimationManager(script) local model = {} function model:StartAnimation(animation, speed, objects, playOnce, reset, blendMultiplier) --some code self.objects = objects local printIt = self.objects[1]:GetKeyValue("name") System:Print(printIt) end function model:DrawAnimation() --some code end return model end The scripts are called like this: function Script:Start() --Load Classes self.loadClass = AnimationManager self.animManager = self:loadClass() --Start Animation self.animManager:StartAnimation(argument1, argument2, ...) end function Script:Draw() --To play an animation self.animManager:DrawAnimation() end I only put the nessecary information in the code block, that you understand what I am talking about. My NPCs have diffrent names in the editor. The moving one is named "Fox" the standing one "Jacob". The class works, that is not the problem. In the AI code I printed the name of the NPC who is calling the StartAnimation() function. It prints "Fox", so the correct NPC is calling StartAnimation(). The NPC called "Jacob" is NOT calling StartAnimation(). The NPC is sending his entity (self.entity) so the animation manager knows on which model to perform the animation. In the animation manager if I print the name of the entity to play the Animation on it prints "Jacob". o.O Why does this happen how is it possible that the two NPC scripts seems to communicate with each other. Why does the AI script of "Jacob" send its information? I am really, really confused. I am pretty sure I am doing something wrong. I watched this behavior before, but now it was the time to ask you guys for help, because I dont find the error. P.S.: In function Script:Start() of the AI script I set self.npcModel[1] = self.entity to be able to play the animation on multiple models at once. self.npcModel is then sent to the animation manager. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted September 13, 2016 Share Posted September 13, 2016 Can't remember exactly what it was, but there was something with tables being shared between scripts if they are not defined within the Start function. Quote Link to comment Share on other sites More sharing options...
Thirsty Panther Posted September 13, 2016 Share Posted September 13, 2016 Is this the one your thinking of Jorn? http://www.leadwerks.com/werkspace/topic/12023-tables-are-global-for-all-scripts/page__hl__tables 1 Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted September 13, 2016 Share Posted September 13, 2016 Yes, thanks Thirsty Panther. I don't know for sure if it is the problem in the OP's scenario, but the 'communication between the entities' he wrote made me immediatly think of that. Quote Link to comment Share on other sites More sharing options...
Phodex Games Posted September 13, 2016 Author Share Posted September 13, 2016 Ok thanks for you answer, but I am still a bit confused. I do not get were exactly the mistake is? I declare my class in the start function as well as the self.playerModel variable, or is the problem the model table I have in my class. So how to fix my issue. Sorry I dont get it completely... EDIT: Oh I had this npcModel variable 2 times at the beginning of the script ^^ well my fault didnt saw that. It works now. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.