Jump to content

[LUA] Weird Variable Behavior


Phodex Games
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

  • Upvote 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...