xtreampb Posted February 17, 2014 Share Posted February 17, 2014 So I have a script attached to my entity. I'm trying to access the same script attached to another entity, but it keeps on saying what i have a null value when trying to access it. I am using LE 3.0 Attached is the script: require "Scripts/Animation/AnimationManager.lua" require "Scripts/Functions/GetEntityNeighbors.lua" Script.teamID=0 --choice Team "Good, Bad, Neutral" Script.enabled=true --bool Script.takeDamage=true --bool Script.attackRng=1.5 --float Script.sightDist=10 --int Script.target="" --entity Script.maxHealth=30 --int Script.health=30 --int function Script:Start() --create the animation manager to handle all animations self.animationManager=AnimationManager:Create(self.entity) end --[[ function Script:UpdateMatrix() end ]]-- --[[ function Script:UpdateWorld() end ]]-- --function Script:UpdateAnimations(int newState)--used to update the animations to the new state --end function Script:CanTakeDamage() return self.takeDamage end function Script:UpdatePhysics() if self.target ~= nil then System:Print(self.entity:ToString() .." has a target") self:Attack() else System:Print(self.entity:ToString() .." has no target") end end function Script:Attack()--used to handle the attack routinue --this check should be done when acquiring targets//JCT if self.target.takeDamage==true then --if our target can take damage --[[this always results to false if i try self.target:CanTakeDamage() or self.target.entity:CanTakeDamage() or self.target.entity.script:CanTakeDamage() it always says that this is trying to evaluate a nil value.--]] local targetPos=self.target.entity:GetPosition(true) --get the position of our target local position=Transform:Point(targetPos.x, targetPos.y, targetPos.z, nil, self.entity)--transform the point from global space to local space to our perspective --rotate to face the target local p0=self.entity:GetPosition(true) local p1=self.target.entity:GetPosition(true) local yaw=Math:ATan2(p1.x-p0.x, p1.z-po.z)-180 yaw=Math:CurveAngle(self.entity:GetRotation().y, yaw, 2) self.entity:SetInput(yaw,0,0,0,false,0) --disable all movement and turn ourselves to face the target --[[ not sure what this does so leaving out for testing//JCT pos=pos * self.entity:GetScale() pos.z=pos.z*-1 ]] if pos.z>0 and pos.z<self.attackRng then --[[ not sure why the bellow test case is revelant//JCT if pos.z>math.abs(pos.x) and pos.z>math.abs(pos.y) then --]] self.target:TakeDamage(10) System:Print(self.target .. " Took Damage") end end end function Script:TakeDamage()--used as a way for this entity to take damage from outside sources end --[[ function Script:Collision(entity, position, normal, speed) end ]]-- function Script:Draw() --update animations self.animationManager:Update() end --[[ function Script:DrawEach(camera) end ]]-- --[[ function Script:Release() end ]]-- --[[ function Script:Cleanup() end ]]-- Quote bool Life() { while(death=false) { if(death==true) return death; } } I have found the secret to infinite life Did I help you out? Like my post! 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.