Page 1 of 1

Strformat() Question

Posted: Sat Mar 07, 2015 3:35 pm
by qcgreywolf
Is there a valid equivalent to the following code?
I can get around this problem by declaring all my hidden Token Properties as local variables in this UDF, but I just got done rewriting all the code to call the properties from the token.

Code: Select all

	[h: output.tip = strformat("<html>
	<table><tr><td colspan=2><b><center>To Hit Roll</center></b></td></tr>
		<tr><td>d20 Roll:</td><td>%{getProperty("toHitRoll")}</td></tr>
		<tr><td>Modifier:</td><td>%{getProperty("toHitModifier")}</td></tr>
	</table></html>")]
Edit: (I pulled out the above snippet and put it into a test macro, and narrowed it down to the getProperty(), strformat does not like it)


Full code in case it helps, but it is just more of the same above.

Code: Select all

[h: gmOnly = isNPC()]

<tr>
<td>
[if(getProperty("criticalHit") == 1 || getProperty("toHitRoll") == 20), code:
{
	[h: output.tip = strformat("<html>
	<table><tr><td colspan=2><b><center>To Hit Rolls</center></b></td></tr>
		<tr><td>d20 Roll:</td><td>%{getProperty("toHitRoll")}</td><td>Threat Roll:</td><td>%{getProperty("criticalThreatRoll")}</td></tr>
		<tr><td>Modifier:</td><td>%{getProperty("toHitModifier")}</td><td>Threat Modifier:</td><td>%{getProperty("criticalThreatMod")}</td></tr>
	</table></html>")]

	<span title="{output.tip}">
	<font color = "FF0000">
		<b>[r: getProperty("attackNumber")]</b>  - [r: if(getProperty("toHitRoll") == 20,"<b>Hit!</b>","Threat")] - [r: getProperty("toHit")] ([r: if(getProperty("criticalHit")==1 || getProperty("toHitRoll") == 20,getProperty("toHitRoll"),"")]) [r: if(getProperty("criticalHit")==1 || getProperty("toHitRoll") == 20,getProperty("criticalThreat"),"")] ([r: if(getProperty("criticalHit")==1 || getProperty("toHitRoll") == 20,getProperty("criticalThreatRoll"),"")])
	</font>
	</span>

};{

	[h: output.tip = strformat("<html>
	<table><tr><td colspan=2><b><center>To Hit Roll</center></b></td></tr>
		<tr><td>d20 Roll:</td><td>%{getProperty("toHitRoll")}</td></tr>
		<tr><td>Modifier:</td><td>%{getProperty("toHitModifier")}</td></tr>
	</table></html>")]

	<span title="{output.tip}">
		<b>[r: getProperty("attackNumber")] - </b> [r: getProperty("toHit")]
		[r: if(getProperty("toHitRoll") == 1, " - CRITICAL MISS! - ", "")]
	</span>

}]
</td>

					<!-- Bulk Formatting 1 -->
[h: output.tip = strformat("<html>
	<table><tr><td colspan=2><b><center>Damage Type: %{getProperty("damageType11")}</center></b></td></tr>
		<tr><td>Damage:</td><td>%{getProperty("damageDice11")} + %{getProperty("TempDamageModifier")}</td><td>Critical Damage:</td><td>%{getProperty("criticalDamageDice11")} + %{getProperty("tempCriticalDamage")}</td></tr>
		<tr><td>Damage Die:</td><td>%{getProperty("unrolledDice11")}</td><td>Threat Multiplier:</td><td>%{getProperty("unrolledDice11")} x %{getProperty("criticalMultiplier")}</td></tr>
	</table></html>")]

<td><span title="{output.tip}">
---- [r: if(getProperty("damageDice11") == 0, "", getProperty("damageDice11") + getProperty("TempDamageModifier"))] [r: if(getProperty("criticalHit") == 1, "(", "")][r: if(getProperty("criticalHit") == 1, getProperty("criticalDamageDice11") + getProperty("tempCriticalDamage"), "")][r: if(getProperty("criticalHit") == 1, ")", "")] [r: if(getProperty("damageType11") == "", "", getProperty("damageType11"))]
</span></td>

[h: output.tip = strformat("<html>
   <table><tr><td colspan=2><b><center>Damage Type: %{getProperty("damageType22")}</center></b></td></tr>
      <tr><td>Damage:</td><td>%{getProperty("damageDice22")}</td></tr>
      <tr><td>Damage Die:</td><td>%{getProperty("unrolledDice22")}</td></tr>
   </table></html>")]

<td><span title="{output.tip}">
 [r: if(getProperty("damageDice22") == 0, "", getProperty("damageDice22"))] [r: if(getProperty("damageType22") == "", "", getProperty("damageType22"))]
</span></td>

[h: output.tip = strformat("<html>
   <table><tr><td colspan=2><b><center>Damage Type: %{getProperty("damageType33")}</center></b></td></tr>
      <tr><td>Damage:</td><td>%{getProperty("damageDice33")}</td></tr>
      <tr><td>Damage Die:</td><td>%{getProperty("unrolledDice33")}</td></tr>
   </table></html>")]

<td><span title="{output.tip}">
 [r: if(getProperty("damageDice33") == 0, "", getProperty("damageDice33"))] [r: if(getProperty("damageType33") == "", "", getProperty("damageType33"))]
</span></td>

[h: output.tip = strformat("<html>
   <table><tr><td colspan=2><b><center>Damage Type: %{getProperty("damageType44")}</center></b></td></tr>
      <tr><td>Damage:</td><td>%{getProperty("damageDice44")}</td></tr>
      <tr><td>Damage Die:</td><td>%{getProperty("unrolledDice44")}</td></tr>
   </table></html>")]

<td><span title="{output.tip}">
 [r: if(getProperty("damageDice44") == 0, "", getProperty("damageDice44"))] [r: if(getProperty("damageType44") == "", "", getProperty("damageType44"))]
</span></td>

[h: output.tip = strformat("<html>
   <table><tr><td colspan=2><b><center>Damage Type: %{getProperty("damageType55")}</center></b></td></tr>
      <tr><td>Damage:</td><td>%{getProperty("damageDice55")}</td></tr>
      <tr><td>Damage Die:</td><td>%{getProperty("unrolledDice55")}</td></tr>
   </table></html>")]

<td><span title="{output.tip}">
 [r: if(getProperty("damageDice55") == 0, "", getProperty("damageDice55"))] [r: if(getProperty("damageType55") == "", "", getProperty("damageType55"))]
</span></td>

[h: totalDamage = getProperty("damageDice11") + if(getProperty("damageDice22") == "", 0, getProperty("damageDice22")) + if(getProperty("damageDice33") == "", 0, getProperty("damageDice33")) + if(getProperty("damageDice44") == "", 0, getProperty("damageDice44")) + if(getProperty("damageDice55") == "", 0, getProperty("damageDice55")) + getProperty("TempDamageModifier")]

[h: output.tip = strformat("<html>
   <table><tr><td colspan=2><b><center>Damage Total</center></b></td></tr>
      <td>%{getProperty("damageDice11")} + %{getProperty("TempDamageModifier")} + %{getProperty("damageDice22")} + %{getProperty("damageDice33")} + %{getProperty("damageDice44")} + %{getProperty("damageDice55")} = %{getProperty("totalDamage")}(%{getProperty("criticalDamageDice11")} + %{getProperty("tempCriticalDamage")}) </td>
   </table></html>")]

<td><span title="{output.tip}">
 [r: totalDamage] [r: if(getProperty("criticalHit") == 1, "(", "")][r: if(getProperty("criticalHit") == 1, getProperty("criticalDamageDice11") + getProperty("tempCriticalDamage"), "")][r: if(getProperty("criticalHit") == 1, ")", "")] damage.
</span></td>

[if(autoCMB == 1), CODE:
{
  [h: output.tip = strformat("<html>
   <table><tr><td colspan=2><b><center>CMB Roll</center></b></td></tr>
      <tr><td>Modifier:</td><td>%{getProperty("CMB")}</td></tr>
      <tr><td>Temporary Modifiers:</td><td>%{getProperty("TempAttackModifier")}</td></tr>
   </table></html>")]

  <td><span title="{output.tip}">
(CMB 
 [r: getProperty("CMBtotal")]</td>
<td>
(
[r: getProperty("CMBroll")]
))
</span></td>
};{}]

[if(SneakAttack > 0), CODE:
{
  [h: output.tip = strformat("<html>
   <table><tr><td colspan=2><b><center>Sneak Attack</center></b></td></tr>
      <tr><td>Sneak Attack Dice:</td><td>%{getProperty("SneakAttack")}d6</td></tr>
   </table></html>")]

  <td><span title="{output.tip}">
- (Sneak Attack [r: getProperty("SADamage")])
  </td>
</span>
};{}]

</tr>

Re: Strformat() Question

Posted: Sat Mar 07, 2015 4:17 pm
by aliasmask
You can't call functions that way in a strformat. I recommend assigning them to variables first and then use the variable in the strformat. There is another option though. You can use %s and then use the getProperty as an argument after the string in the strformat, like this strformat("value: %s",getProperty("value")). It goes in order, so the first %s matches the first argument after the string, the 2nd matches the 2nd and so on.

Re: Strformat() Question

Posted: Sat Mar 07, 2015 4:22 pm
by qcgreywolf
Excellent, thank you for the quick answer.

I am going back through and just declaring the vars first at the beginning of the code. I guess the code is a little easier to read that way anyway. I was just trying to be clever, which usually breaks my code :)

Re: Strformat() Question

Posted: Sat Mar 07, 2015 4:43 pm
by aliasmask
Defining your variables at the beginning is a good idea. I often refer people to this for best practices: http://forums.rptools.net/viewtopic.php ... 81#p233681