Initiative calculations in 1.1b2

Discussion of initiative tool.

Moderators: dorpond, Azhrei

Post Reply
User avatar
drswoboda
Dragon
Posts: 313
Joined: Tue Apr 25, 2006 12:54 pm
Location: Milwaukee, WI

Initiative calculations in 1.1b2

Post by drswoboda »

Hi Jay,

I am trying to figure out your Initiative calculations in the Init Tool 1.1. Default D&D settings file, and I don't "get" what is going on there. Have you checked that bit of code lately? It seems a bit strange to me. I have gone back to your original file, just to make sure I didn't mess something up with my work on SWS.

So here are my observations on this issue.

I start with a character with 12's in all stats so the Dex Mod is +1.

I press the INIT button to roll initiative and get a 19, which then shows in the log, the Total box and after the name in list. So far so good. Now I want to see that values that were used so I go to the properties for the character by double-clicking in the list. I open up the Combat tree, then the Initiative Modifier tree. Then I look at the values and they make no sense too me. They are as follows:

Initiative = 19
Initiative Modifier = 0
Initiative Modifier (tree) = 1
Base = 0
Current = 1
Mods = 0
Modifiers = null
Temp = 0
Roll Initiative = 9
Display Roll Initiative = Roll initiative: 6

Now looking at the XML I see:

Code: Select all

    
<property name="itInitiative" type="NUMBER" group="Combat" display="Initiative"><description>Initiative for this creature.</description></property>
    <property name="itInitiativeModifier" type="SCRIPT" group="Combat" display="Initiative Modifier">
      <description>The initiative modifier for this creature.</description>
      <script>root.initModifier.current</script>
    </property>
    <property name="initModifier" type="MAP" group="Combat" display="Initiative Modifier" extends="modifiableValue">
      <description>The initiative modifier for this creature.</description>
      <properties>
        <property name="current" type="SCRIPT">
          <description>Current initiative modifier.</description>
          <script>root.dex.currentMod + totalModifiers + userMod</script>
        </property>
        <property name="rollInitiative" type="SCRIPT">
          <description>Roll the initiative and set it</description>
          <script cacheable="false">root.itInitiative = (1d20 + current)</script>
        </property>
        <property name="displayRollInitiative" type="SCRIPT">
          <description>Display the initiative roll.</description>
          <script cacheable="false">'Roll initiative: ' + rollInitiative</script>
        </property>
      </properties>
    </property>
So my question is where did 19 come from? The dice roll would have to be 18 (+ 1 for DexMod), but rollInitiative = (1d20 + current (1)) = 9 which would indicate an eight was rolled. and then it is shown as a total of 6 displayRollInitiative and then as 19 in the log and other UI elements.

So what is really going on here? Then I noticed that as you click on some of the properties in the tree they change values! What is that? That seems very strange. Why would you want those values to change by just clicking the properties?

I'm sure you are already aware of some of this, but if not I'd take a look at this for the next build.

Actually, this part is the first area where it all really seems a bit convoluted and a bit confusing to the user. As you develop this code, I feel pretty sure that you need to come up with a better way to generate/display the dice rolls used here. Users will want assurance of how that number fits into the chain of events. As it is now, perhaps due to my lack of understanding this bit, there is not a clear indicator of the die roll. Not to mention the changing numbers as you view the properties tree and the possible error in this calculation.

For my SWS hacked sheet my calculation is going to be very simple as it is the final total of the characters Initiative Skill, and that is already calculated before I get to the initiative code. I will just need to roll a d20 and add them together for my total Initiative.

But before I can write that code I need to understand what your existing initiative code is actually doing so I can fudge it for Star Wars rules.

One other note while I am here. Going back to the original settings file, I noticed that the editor had removed or changed my code from this starting base. In particular, the 'cacheable="false"' lines have been stripped out in my current version. This must have happened during the early stages when I still trying to do the work in the editor. I am now doing everything in Notepad++ as you suggested earlier. My code doesn't crash with those changes, so it must be alright, but I did not make those changes to the file.

Thanks for listening.
-David

User avatar
jay
RPTools Team
Posts: 1767
Joined: Tue Feb 07, 2006 1:07 am
Location: Austin, Tx

Post by jay »

I'm guessing that the problem is the changing values that you are seeing. The way that the script properties work is that may be evaluated every time they are read. The cacheable attribute controls this. When it is set to true the script values only change when a property in the tree changes. When it is set to false it is changed every time it is read. So every time the tree is redrawn the scripts which aren't cacheable are will be reevaluated. Since I only set cacheable=false when they have a random value in them they will change a lot. So if you are looking at the tree and trying to figure things out with the non=cached you're going to have a rough time. The 'Roll initiative' and 'Display Roll Initiative' will most likely change every time they are read so you can ignore them.

I'm not sure why 'Initiative Modifier' & "Initiative Modifier' in the tree are different. It may be a bug in the form that displays the value. That is why I added the tree support in the first place.

Search for 'DETERMINE_INITIATIVE' to see the script that is used internally by IT to roll initiative when you click on start encounter. The 'Roll Initiative' and 'Display Roll Initiative' proeprties are only used to support the button on form so that the GM can re-roll any initiative they don't like.

I took a look at what I have for the 'DETERMINE_INITIATIVE' now and the script used to calculate the initiative is:

Code: Select all

1d20 + combatant.itInitiativeModifier
which means that there isn't a way to tell what the original roll was from a start encounter. That could be fixed by adding a property for the roll and then setting it in the script. Try creating a property called 'lastInitRoll' and write the script this way so that you have that number saved:

Code: Select all

(lastInitRoll = 1d20) + combatant.itInitiativeModifier
I couldn't test this since I'm still trying to reconstruct my project from the dead computer's drive, but it should work.

The loss of the cacheable flag on a save is probably a bug, I'll check into it.

User avatar
drswoboda
Dragon
Posts: 313
Joined: Tue Apr 25, 2006 12:54 pm
Location: Milwaukee, WI

Post by drswoboda »

Thanks Jay, I'll try and absorb this information and get my Initiative for SWS working.

I need to look a bit closer at the original D&D data file, but I think I noticed another thing that might need tweaking. When you start an initiative session, you can use the button to reroll, but it doesn't look like adding a Temp modifier to the input box makes a change to the rolled Initiative until you press the button again.

Is there a way to just bump up the value (edit) during the round? It didn't seem to work when I tried it earlier. I have stripped out a bunch of stuff in my settings, so I need to go back a check the original code.

Thanks again.

User avatar
drswoboda
Dragon
Posts: 313
Joined: Tue Apr 25, 2006 12:54 pm
Location: Milwaukee, WI

Post by drswoboda »

Hi Jay,

I just did a little testing and there is definately either a display or calucualtion issue with those changing values.

Code: Select all

		<property name="initModifier" type="MAP" extends="modifiableValue" group="Combat">
        <description>The initiative modifier for this creature.</description>
        <properties>
          <property name="current" type="SCRIPT">
            <description>Star Wars Saga: REMOVED totalModifiers. Current initiative modifier. old formula root.dex.currentMod + totalModifiers + userMod</description>
            <script>root.initiative.current</script>
          </property>

          <property name="lastInitRoll" type="SCRIPT">
            <description>Star Wars Saga: Holds last 1d20 die roll</description>
			<script>current + initRoll</script>
          </property>
		  
          <property name="initRoll" type="SCRIPT">
            <description>Star Wars Saga: 1d20 die roll</description>
            <script>1d20</script>
          </property>		  

In that partial code snippet, root.initiative.current evaluates to -2 for the skill.

If I run this code and go to the properties dialog and click around the values, sometimes the result is correct and others it is incorrect. (usually by a large value). I'm guessing your right and it is a display issue.

However, it rasies an importtant question. That being, when is the random dice roll being made. I think you stated it is rolled at each display of the property. Is that really a good way to do this? It seems to me, that the roll should only be made when I request a die roll be made. In the case of the CharSheet, when I either press the INIT button or when I ask for the start of a new round of encounters. At no other time should a roll value change, unless I call for it.

Having the random number being generated on display of properties seems frought with errors down the road. Now not being a programmer, there are surely reasons for doing it the way it is, but it seems 'wrong' too me. I think there should be a trigger for that die roll, or else the potential values to be displayed on a sheet might be incorrect or updated incorrectly.

-David

User avatar
jay
RPTools Team
Posts: 1767
Joined: Tue Feb 07, 2006 1:07 am
Location: Austin, Tx

Post by jay »

drswoboda wrote:However, it rasies an importtant question. That being, when is the random dice roll being made. I think you stated it is rolled at each display of the property. Is that really a good way to do this? It seems to me, that the roll should only be made when I request a die roll be made. In the case of the CharSheet, when I either press the INIT button or when I ask for the start of a new round of encounters. At no other time should a roll value change, unless I call for it.
The problem is that there is only one way to access a property value and that way is to read it. There isn't any way to tell the difference between reading a value by executing a script and reading the old value. So it has to be evaluated every time it is read. These properties are not used by IT to start the encounter. That uses a separate script. These properties were just added to help with programming buttons. When I first wrote the form support that was the only way to call a script. I've added the CharSheetXxx components since then to fix the problem and support for calling scripts that are not attached to propertie. So you can actually do things how you suggest w/o using scripts in the properties. I just never went back and removed all of the old stuff.
drswoboda wrote:Having the random number being generated on display of properties seems frought with errors down the road. Now not being a programmer, there are surely reasons for doing it the way it is, but it seems 'wrong' too me. I think there should be a trigger for that die roll, or else the potential values to be displayed on a sheet might be incorrect or updated incorrectly.
Then you need to make sure that you don't create any property that has a random value in it. If you do you will need to make sure it doesn't get accessed unless you want it to be accessed. Setting visibility="BY_NO_ONE" keeps IT from reading it. If you don't add it as a text field or label to your form then it won't be read automatically by the form. If you add it as a button to your form it will only be read when the button is pressed, which I think is what you are asking for above.

User avatar
jay
RPTools Team
Posts: 1767
Joined: Tue Feb 07, 2006 1:07 am
Location: Austin, Tx

Post by jay »

You might try to fix your code above by adding a numeric property:

Code: Select all

<property name="initDieRoll' type="NUMBER"/>
and than change the 'lastInitRoll' script to be

Code: Select all

current + initDieRoll
then rewrite the 'initRoll' property to be

Code: Select all

{property name="initRoll" type="SCRIPT" visibility="BY_NO_ONE"}
  {script cacheable='false'}(initDieRoll = 1d20)</script>
{/property}

* Note: I used {} instead of <> because the wiki was eating them when I posted.
Since the 'initRoll' property is hidden it can only be viewed and then changed from a form. If you only reference the 'initDieRoll' value from a button on the form then it will only be changed when the button is pressed.

User avatar
drswoboda
Dragon
Posts: 313
Joined: Tue Apr 25, 2006 12:54 pm
Location: Milwaukee, WI

Post by drswoboda »

Cool, I'll try that suggested code.

Re: code not posting.
I have found that you have to check the box "Disable HTML in this post" when posting or the XML gets chopped. . .

User avatar
drswoboda
Dragon
Posts: 313
Joined: Tue Apr 25, 2006 12:54 pm
Location: Milwaukee, WI

Post by drswoboda »

Hi Jay,

I can't get the last bit of code you posted to work.

Code: Select all

	  <property name="initModifier" display="Initiative Current" type="MAP" group="Combat">
        <description>The initiative modifier for this creature.</description>
        <properties>
          <property name="current" type="SCRIPT">
            <description>Star Wars Saga: Current initiative modifier + user temporary mods.</description>
            <script>root.initiative.current + userMod</script>
          </property>
          <property name="userMod" display="Temp" type="NUMBER">
            <description>A user modifier applied to the value</description>
          </property>
		  
          <property name="initDieRoll" type="NUMBER">
            <description>TEST Star Wars Saga: </description>
          </property>
          <property name="lastInitRoll" type="SCRIPT">
            <description>TEST Star Wars Saga: Holds last 1d20 die roll + current.</description>
			<script>current + initDieRoll</script>
          </property>		  
		  <property name="initRoll" type="SCRIPT" visibility="BY_NO_ONE"> 
		    <description>TEST (initDieRoll = 1d20)</description>
			<script cacheable="false">(initDieRoll = 1d20)</script> 
		  </property>		    

          <property name="rollInitiative" type="SCRIPT">
            <description>Roll the initiative and set it. Old Formula = root.itInitiative = (1d20 + current)</description>
            <script cacheable="false">root.itInitiative = (1d20 + current)</script>
          </property>
          <property name="displayRollInitiative" type="SCRIPT">
            <description>Display the initiative roll.</description>
            <script cacheable="false">&apos;Roll initiative: &apos; + rollInitiative</script>
          </property>
		  
        </properties>
      </property>
It appears that the formula (initDieRoll = 1d20) is failing. If I remove the = 1d20 then it evaluates, but with the = 1d20 it doesn't work.

Thanks,
-David

User avatar
jay
RPTools Team
Posts: 1767
Joined: Tue Feb 07, 2006 1:07 am
Location: Austin, Tx

Post by jay »

I'll have to take a look into things. Last time I checked the = sign was working w/in the parser. Are you running IT with a console? If so, are you getting an exception?

User avatar
drswoboda
Dragon
Posts: 313
Joined: Tue Apr 25, 2006 12:54 pm
Location: Milwaukee, WI

Post by drswoboda »

Hi Jay,

I'll enable the console and report back. Thanks.
-David

Post Reply

Return to “InitiativeTool”