Thread: Trying To Extend A Definition
-
May 15th, 2020, 09:59 #11
- Join Date
- Mar 2020
- Location
- Sydney, Australia
- Posts
- 247
-
May 15th, 2020, 10:03 #12
Yes I noticed you were using that in the onInit function. But, all that does is run the onInit function. What else is in the original script? None of that will be run unless you explicitly call it via the super. object.
Sorry, I’m working blind here as I have no idea what’s in the original script.Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
-
May 15th, 2020, 10:06 #13
- Join Date
- Mar 2020
- Location
- Sydney, Australia
- Posts
- 247
The original script is from the SavageWorlds ruleset so I would assume I cannot post it here.
The onInit() there sets up the derived stat and calls its own update function from within the onInit().
So I would assume that code would run from my onInit() using the super call.
Right now I am just trying to get the derived statistic to work (as in calculate correctly) and print a message showing that it executed the onInit().
I will worry about the onChange stuff later.
Thanks,
D
-
May 15th, 2020, 10:10 #14
OK, so let’s take a step back... let’s see if super is available. Remove the if super... in your onInit code and just call super.onInit() straight off. If it fails with a nil exception then it can’t access the super object at that point. And we'll have to identify where the original script info is in the hierarchy.
Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
-
May 15th, 2020, 10:14 #15
- Join Date
- Mar 2020
- Location
- Sydney, Australia
- Posts
- 247
The check for super and super.onInit is successful - I put a debugging message inside that IF statement, so I have a feeling that perhaps the script is being placed in the wrong location.
It would be awesome if there was a way to look at generated XML at any stage during execution.
Thanks,
D
-
May 15th, 2020, 10:37 #16
What XML do you currently have?
Is <template name="derivedstat_capacity"> your own code or is it somewhere else and you're layering on top of that?Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
-
May 15th, 2020, 10:53 #17
- Join Date
- Mar 2020
- Location
- Sydney, Australia
- Posts
- 247
It is my own code ... are you looking at the SavageWorlds ruleset at all?
I will try and explain how this bit works ...
Code:First define the derived statistic ... <template name="derivedstat_capacity"> <derbase> <setup> <attribute> <half>strength</half> </attribute> <modifier>2</modifier> </setup> </derbase> </template> In another file extend the template ... <template name="derivedstat_capacity"> <derbase> <script file="charsheet/scripts/template_capacity.lua" /> </derbase> </template>
Thanks,
D
-
May 15th, 2020, 10:59 #18
I am now in front of a computer and can see the SavageWorlds ruleset.
OK, that's what I was thinking. As you're extending your derivedstat_capacity template which is an extended derbase template. Calling superonInit() in charsheet/scripts/template_capacity.lua will call the onInit function in derivedstat_capacity not in derbase.
Does that make sense?
You don't need to define derivedstat_capacity and then extend it with the same name within your code (unless there's a specific reason to do that, in which case I'd recommend making a new template not extend and existing one).
Try this:
Code:<template name="derivedstat_capacity"> <derbase> <script file="charsheet/scripts/template_capacity.lua" /> <setup> <attribute> <half>strength</half> </attribute> <modifier>2</modifier> </setup> </derbase> </template>
Last edited by Trenloe; May 15th, 2020 at 11:02.
Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
-
May 15th, 2020, 11:02 #19
- Join Date
- Mar 2020
- Location
- Sydney, Australia
- Posts
- 247
Okay, I can understand that.
I was trying to follow the structure of the Savage Worlds ruleset so that the extension will be "readable" by anyone who has access to the ruleset and has explored it.
Is there anyway for me to do it that way?
Orderly structure is important to me - to a degree.
Thanks,
D
-
May 15th, 2020, 11:07 #20
I don't think this situation is the same as the Savage Worlds ruleset. The Savage Worlds ruleset adds new scripts into a new template which can then call super. directly in a template above. What yo're doing is creating a template called derivedstat_capacity and then overriding that with a template of exactly the same name. There's no need to do that in the same extension. There would only be a need to do that if you're layering a ruleset/extension in top of a base template. And, as I have mentioned, this means it breaks the inherited script hierarchy.
My recommendation would do what is simpler and more striaghtforward. Don't try to complicate things. Doing it in what appears to be a similar way to the Savage Worlds rulesets may not be the right way (as is the case here). Anywhere you have multiple template layers is going to make it more complex for anyone looking at your code. Keep template layering to a minimum.Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks