Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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?
- EndeavourToday at 1:43 PM
- Is there a List of all the actionsNames a character can play ?
- CamenwolfToday at 2:11 PM
- 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()?
- function <myscript>:GetChild(myTable, name)
- for k, v in pairs(myTable) do
- if v:GetName() == name then return v end
- end
- end
- whosamericaToday at 2:27 PM
- @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.
- CamenwolfToday at 2:31 PM
- @whosamerica Well, I mean the function I posted above does successfully reference the child. So, using that function if, for example, I say
- local myChild = self:GetChild(self:GetEntity():GetChildren(), "Charlie")
- mochiToday at 2:31 PM
- You can also add children into script properties
- CamenwolfToday at 2:31 PM
- Then from that point on myChild is a reference to the child entity named Charlie.
- But I just figured there was a more elegant way to do it.
- mochiToday at 2:31 PM
- If you don't want it cluttering up the UI you can set it and then set editable = "false"
- CamenwolfToday at 2:32 PM
- oh, as a property?
- mochiToday at 2:32 PM
- Yup
- CamenwolfToday at 2:32 PM
- type = "entity"?
- Then I have to drag the child into the property, or is there a way to reference it in the property declaration in code?
- mochiToday at 2:36 PM
- Need to drag it in/select
- CamenwolfToday at 2:41 PM
- 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.
- mochiToday at 3:06 PM
- You can set editable = false and it won't show that property on the ui
- CamenwolfToday at 3:07 PM
- @mochi Then how do I assign it?
- mochiToday at 3:08 PM
- You assign it first, then set editable as false and it'll keep the value you assigned
- CamenwolfToday at 3:08 PM
- ah, so in the template it will forever be that child.
- 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.
- function <myScriptName>:GetChild(name)
- local myTable = self:GetEntity():GetChildren()
- for k, v in pairs(myTable) do
- if v:GetName() == name then return v end
- end
- end
- mochiToday at 3:10 PM
- Yup
- CamenwolfToday at 3:10 PM
- so to get a child entity I just say self:GetChild("Charlie") and it returns the child named "Charlie"
- Seems like this should be a built in method. But the function is short enough.
- mochiToday at 3:13 PM
- Otherwise I'd recommend something like
- for i = 1, #self:GetChildren() do
- self.children[self:GetChildren()[i]:GetName()] = self:GetChildren()[i]
- end
- in Init
- Then no function necessary and you just reference like self.children.CHILD_NAME
- CamenwolfToday at 3:15 PM
- ah yeah. sweet! very elegant.
- so the # is sort of like the "length" method in say javascript?
- mochiToday at 3:16 PM
- Only problem with that is if the entity gets renamed then you need to update your strings
- CamenwolfToday at 3:16 PM
- It means the number of elements in this table?
- mochiToday at 3:16 PM
- With properties you don't need to worry about that
- so the # is sort of like the "length" method in say javascript?
- @Camenwolf yup
- CamenwolfToday at 3:17 PM
- Good stuff. Thanks, mochi.
- DaigorōToday at 3:51 PM
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement