Slastraf Posted August 22, 2015 Share Posted August 22, 2015 function Script:CreateNewParent(pName,x,y,z) self.parent(pName)=nil self.parent(pName) = Model:Box() self.parent(pName):SetPosition(x,y,z) end I think its self explaining, I want to make my script more optimized so how do you make a new object with a pName as name? Quote Link to comment Share on other sites More sharing options...
beo6 Posted August 22, 2015 Share Posted August 22, 2015 (edited) i hope i understand it correctly what you are trying to do. you can do the following: function Script:CreateNewParent(pName,x,y,z) --self.parent[pName]=nil self.parent[pName] = Model:Box() self.parent[pName]:SetPosition(x,y,z) end after a self:CreateNewParent('yourchoosenname', 0, 0, 0) you should be able to access it with self.parent.yourchoosenname //Edit: if you want to make the current entity a parent of the new one you would have to add self.entity:SetParent(self.parent[pName]) after you created it. Edited August 22, 2015 by beo6 1 Quote Link to comment Share on other sites More sharing options...
Slastraf Posted August 22, 2015 Author Share Posted August 22, 2015 i hope i understand it correctly what you are trying to do. you can do the following: function Script:CreateNewParent(pName,x,y,z) --self.parent[pName]=nil self.parent[pName] = Model:Box() self.parent[pName]:SetPosition(x,y,z) end after a self:CreateNewParent('yourchoosenname', 0, 0, 0) you should be able to access it with self.parent.yourchoosenname //Edit: if you want to make the current entity a parent of the new one you would have to add self.entity:SetParent(self.parent[pName]) after you created it. I want to make a joint, I already have implemented CreateNewJoint, the joints dont need different names but the parts of the thing that I want to make do. But thank you for answering Quote Link to comment Share on other sites More sharing options...
Einlander Posted August 22, 2015 Share Posted August 22, 2015 Looks like you might want to make linked lists.... But for named lists use [] around a string Quote Link to comment Share on other sites More sharing options...
Slastraf Posted August 23, 2015 Author Share Posted August 23, 2015 Looks like you might want to make linked lists.... But for named lists use [] around a string So now I have the error that self.parent is a nil value, but since I want to create a self.parent inside the function, it is not very usable. So how do I make sure that I create an entity inside the function and not inside the start() function? I also tried to put it in an array table.insert(a,self.parent[pName]) (If theres an other way that would be better) Quote Link to comment Share on other sites More sharing options...
Einlander Posted August 23, 2015 Share Posted August 23, 2015 It might help if you asked the question in the other thread so people can see exactly what you are trying to do. So let me try to understand. You want to specify a start and end point. Then you want to have joints automatically generated in between? So wouldn't you specify the start point and then end point, then divide the distance between them by the number of ball joints you need. The first ball joint would be the child of the start point, the second would be the child of the first and parent of the third and so on. when you get to the last one you assign that to be the parent of the end point. I would do some pseudo -code, but I haven't slept in a while.... 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.