Marcousik Posted December 30, 2017 Share Posted December 30, 2017 Hello people, I read a lot of people who encountered problems that the start functions of the children would not fire... I encounter today the opposite problem. All my scripts are written like that the main character start function fires at first and then the start() of the children. Now it seems like Leadwerks let run first the children start() functions that return a many errors as my variables are in the main start() declared... That's penible because it seems there is no order control about this ? thx Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 2, 2018 Share Posted January 2, 2018 Yeah I have been bitten by this problem several times. What you can do to solve this is add a bool variable IsInit at the end of each start function and set it to true when the end of the start functions has been reached. When you are in a child, check if the parent has this IsInit variable set to true. If not, then perform an init function on the parent first. 1 Quote Link to comment Share on other sites More sharing options...
Marcousik Posted January 3, 2018 Author Share Posted January 3, 2018 yes ok thx Quote Link to comment Share on other sites More sharing options...
Josh Posted January 4, 2018 Share Posted January 4, 2018 The entities may have Start() called in any order. I have never had a problem writing a script to account for this, but if you have a concrete example of a problem please post it. If the problem is solved in code then the script just works everywhere. If a complicated ordering system were introduced in the editor then you would have to adjust the order for every map you use the script in. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Marcousik Posted January 5, 2018 Author Share Posted January 5, 2018 Yes Josh that's right... I got one time the problem with childs using variables defined in the parent start script like this: Child:GetParent().script.variable This "variable" should not be the same if the parent start() function fires first. The same with Global variables defined in the parent start function and that could be used in children start()... BUT I encounter the problem only one time, just after saving my player-character as Prefab, the same map that runs 100x without bugs didn't anymore. This occurs only one time so it's not so heavy for me, I could restore the character from a another map, saving it as prefab without problem. I don't know. Little bit strange. Quote Link to comment Share on other sites More sharing options...
Josh Posted January 6, 2018 Share Posted January 6, 2018 On 1/5/2018 at 1:32 PM, Marcousik said: Yes Josh that's right... I got one time the problem with childs using variables defined in the parent start script like this: Child:GetParent().script.variable This "variable" should not be the same if the parent start() function fires first. The same with Global variables defined in the parent start function and that could be used in children start()... BUT I encounter the problem only one time, just after saving my player-character as Prefab, the same map that runs 100x without bugs didn't anymore. This occurs only one time so it's not so heavy for me, I could restore the character from a another map, saving it as prefab without problem. I don't know. Little bit strange. Normally we solve issues like this with the following design: function Script:Start() local parent = self.entity:GetParent() if parent.script~=nil then if type(parent.script.Initialize)=="function" then parent.script:Initialize() end end --do some other stuff to the parent end And in the parent script: function Script:Start() self:Initialize() end function Script:Initialize() if self.initialized then return end self.initialized = true --do some other stuff end Hopefully that is clear. Note the need for something like this is very rare. None of the default scripts that ship with Leadwerks need anything like this. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Marcousik Posted January 6, 2018 Author Share Posted January 6, 2018 Thx yes that is very clear Quote Link to comment Share on other sites More sharing options...
Josh Posted January 6, 2018 Share Posted January 6, 2018 This is even a little simpler: function Script:Start() local parent = self.entity:GetParent() if parent.script~=nil then if type(parent.script.Start)=="function" then parent.script:Start() end end --do some other stuff to the parent end function Script:Start() if self.initialized then return end self.initialized = true --do some other stuff end 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. 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.