Jump to content

Program is break without any prompting


NoIE
 Share

Recommended Posts



code:
Script.parentObj = nil--entity

function Script:Start()
   self.center = self.entity:FindChild("center")
   if self.center~= nil then
       local pos = self.center:GetPosition(true)        
       self.jointBall = Joint:Ball(pos.x, pos.y,pos.z,self.entity,self.parentObj)    


    ------------------------------------------------------------------------------------------------------
    -- There are also "self.parentObj:Get...", but it will not cause problems.
       self.length = pos:DistanceToPoint(self.parentObj:GetPosition(true))
    ------------------------------------------------------------------------------------------------------

   end
end

--[[function Script:Collision(entity, position, normal, speed)
   --if speed> 0.01  and entity.script.tag ~= nil and entity.script.tag == "player" then

   --    entity.script:TakeDamage(3)

   --end
end]]--

function Script:UpdatePhysics()
   local pp = self.parentObj:GetPosition(true)
   local cp = self.center:GetPosition(true)
   local d = cp
   local length = d:Length()
   --if length > self.length+0.1 then
   --    local np =  pp + d:Normalize()*self.length - (cp - self.entity:GetPosition(true))
   --    self.entity:SetPosition( (self.entity:GetPosition(true)*3 + np  )/4 , true)
   --end
end



When I commented " local pp = self.parentObj:GetPosition(true)", it can run, otherwise break immediate. It without any warning.

post-12936-0-43515100-1418403285.gif

  • Upvote 1

Please forgive my poor English.

 

post-12936-0-43515100-1418403285.gif

Link to comment
Share on other sites

What did you link to parentObj in the editor? If it's csg then it needs a mass or script attached otherwise it won't be treated as a valid entity as it gets collapsed into nothingness (I don't know, I hear it gets collapsed and not sure what that means but I know it means it's not treated as an entity).

Link to comment
Share on other sites

What did you link to parentObj in the editor? If it's csg then it needs a mass or script attached otherwise it won't be treated as a valid entity as it gets collapsed into nothingness (I don't know, I hear it gets collapsed and not sure what that means but I know it means it's not treated as an entity).

 

My program will start running and then close immediately. I think I linked parentObj, Because Start function uses parentObj.

 

I also checked the editor. Just now, I tried to remove the link, and then I find

Script Error

 

 

attempt to index field 'parentObj' (a nil value)

 

Line 12

Please forgive my poor English.

 

post-12936-0-43515100-1418403285.gif

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...