Advertisement
otorp2

craygetchld

Aug 2nd, 2020
1,880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.72 KB | None | 0 0
  1. Can someone talk to me a little about design time code?  Apart from the simulate property, is there a way to write code that runs at design time.  If not, then can I access the simulate property from code, so that I can say I want this code to run at design time, but not this code?
  2. EndeavourToday at 1:43 PM
  3. Is there a List of all the actionsNames a character can play ?
  4. CamenwolfToday at 2:11 PM
  5. GetChildren() returns a table of children.  I can't figure out any built in way to reference a specific child by name, and the table seems to be indexed by integers.  The documentation says the order of that table is not guaranteed which means that I can't reference the child entity that I want by its index.  I wrote this little function to get the specific child that I'm looking for, but I feel there is a more elegant way to do this.  Get Children doesn't seem to accept a parameter for a specific child, and there is no GetChild() method, so how do I get a child entity out of the table returned by GetChildren()?
  6. function <myscript>:GetChild(myTable, name)
  7.     for k, v in pairs(myTable) do
  8.         if v:GetName() == name then return v end
  9.     end
  10. end
  11. whosamericaToday at 2:27 PM
  12. @Camenwolf iirc children can only be referenced by parents or other entities by using sends or event sends. I could be wrong, buy for every situation where I've had to be like "if child has 'x' then parent does 'y'" I've had to create either a Findscriptproperty on the parent and create a Boolean to reference on the child or use the send or event functions to send information from the child to the parent.
  13. CamenwolfToday at 2:31 PM
  14. @whosamerica Well, I mean the function I posted above does successfully reference the child.  So, using that function if, for example, I say
  15. local myChild = self:GetChild(self:GetEntity():GetChildren(), "Charlie")
  16. mochiToday at 2:31 PM
  17. You can also add children into script properties
  18. CamenwolfToday at 2:31 PM
  19. Then from that point on myChild is a reference to the child entity named Charlie.
  20. But I just figured there was a more elegant way to do it.
  21. mochiToday at 2:31 PM
  22. If you don't want it cluttering up the UI you can set it and then set editable = "false"
  23. CamenwolfToday at 2:32 PM
  24. oh, as a property?
  25. mochiToday at 2:32 PM
  26. Yup
  27. CamenwolfToday at 2:32 PM
  28. type = "entity"?
  29. Then I have to drag the child into the property, or is there a way to reference it in the property declaration in code?
  30. mochiToday at 2:36 PM
  31. Need to drag it in/select
  32. CamenwolfToday at 2:41 PM
  33. Hmm.  Well, that certainly is a faster, more elegant way to do it.  But what you said about cluttering up the UI is correct.  I'm building an asset that I want to upload as a package.  My vision is a super user friendly, no code package to procedurally generate things.  I want to only expose functionality to the end user through the UI that they are meant to configure.  So I guess short of a built in "GetChild()" or GetChildren(parameter) function, I'll just leverage the function I posted.  I think a re-usable script full of helper functions may be called for.
  34. mochiToday at 3:06 PM
  35. You can set editable = false and it won't show that property on the ui
  36. CamenwolfToday at 3:07 PM
  37. @mochi Then how do I assign it?
  38. mochiToday at 3:08 PM
  39. You assign it first, then set editable as false and it'll keep the value you assigned
  40. CamenwolfToday at 3:08 PM
  41. ah, so in the template it will forever be that child.
  42. Actually I just fixed that function to where you don't even pass it a table.  You just pass it the name of the child and it returns the entity.
  43. function <myScriptName>:GetChild(name)
  44.     local myTable = self:GetEntity():GetChildren()
  45.     for k, v in pairs(myTable) do
  46.         if v:GetName() == name then return v end
  47.     end
  48. end
  49. mochiToday at 3:10 PM
  50. Yup
  51. CamenwolfToday at 3:10 PM
  52. so to get a child entity I just say self:GetChild("Charlie") and it returns the child named "Charlie"
  53. Seems like this should be a built in method.  But the function is short enough.
  54. mochiToday at 3:13 PM
  55. Otherwise I'd recommend something like
  56. for i = 1, #self:GetChildren() do
  57.  self.children[self:GetChildren()[i]:GetName()] = self:GetChildren()[i]
  58. end
  59. in Init
  60. Then no function necessary and you just reference like self.children.CHILD_NAME
  61. CamenwolfToday at 3:15 PM
  62. ah yeah.  sweet!  very elegant.
  63. so the # is sort of like the "length" method in say javascript?
  64. mochiToday at 3:16 PM
  65. Only problem with that is if the entity gets renamed then you need to update your strings
  66. CamenwolfToday at 3:16 PM
  67. It means the number of elements in this table?
  68. mochiToday at 3:16 PM
  69. With properties you don't need to worry about that
  70. so the # is sort of like the "length" method in say javascript?
  71. @Camenwolf yup
  72. CamenwolfToday at 3:17 PM
  73. Good stuff.  Thanks, mochi.
  74. DaigorōToday at 3:51 PM
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement