STAR TREK 2d20
Page 2 of 3 First 123 Last
  1. #11

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247
    Quote Originally Posted by Trenloe View Post
    The script tag in the later defined template XML overrides the script data from the earlier defined template (earlier in the ruleset/extension initialization order). But... the original code is available via the super object.

    If you want some of the original functions to run, you’ll need to call them from the new script. For example, if you have an onValueChanged event function in the original script you want to run, you’ll need to call it from the new script onValueChanged event:
    Code:
    function onValueChanged()
      if super and super.onValueChanged then
        super.onValueChanged();
      end
    end
    If you notice the onInit that I posted earlier, I am doing that (at least for this test) - thus the initialisation of the derived statistic should occur using the old code as well yes?

    Thanks,
    D

  2. #12
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,411
    Quote Originally Posted by UrsaTeddy View Post
    If you notice the onInit that I posted earlier, I am doing that (at least for this test) - thus the initialisation of the derived statistic should occur using the old code as well yes?

    Thanks,
    D
    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!

  3. #13

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247
    Quote Originally Posted by Trenloe View Post
    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.
    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

  4. #14
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,411
    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!

  5. #15

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247
    Quote Originally Posted by Trenloe View Post
    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.
    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

  6. #16
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,411
    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!

  7. #17

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247
    Quote Originally Posted by Trenloe View Post
    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?
    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>
    That's about it for the XML.

    Thanks,
    D

  8. #18
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,411
    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!

  9. #19

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247
    Quote Originally Posted by Trenloe View Post
    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.

    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>
    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

  10. #20
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,411
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
DICE PACKS BUNDLE

Log in

Log in