MapTool 1.3 Development Build 49

New build announcements plus site news and changes.

Moderators: dorpond, trevor, Azhrei, Craig

nwelte1
Giant
Posts: 151
Joined: Mon Nov 19, 2007 10:52 pm

Re: MapTool 1.3 Development Build 49

Post by nwelte1 »

Craig wrote:
nwelte1 wrote:Macro is real simple..... [h, if(isPropertyEmpty("XP")): XP="XPC=0; XPN=0"]. I run the macro and it works perfectly. I then delete the contents of the XP property and rerun the macro and the property remains blank
The token property is blank after you delete it, i.e. "" which is different from empty. If you want to "empty" the property use the resetProperty() function. If you need to check for an empty string use if(XP == "").

Empty in this case means it has never been set, or has been reset.
But my prior uses of if the isPropertyEmpty() function have never ran into this problem when I cleared the properties... Which I am routinely doing.

Craig
Great Wyrm
Posts: 2107
Joined: Sun Jun 22, 2008 7:53 pm
Location: Melbourne, Australia

Re: MapTool 1.3 Development Build 49

Post by Craig »

nwelte1 wrote:
Craig wrote:
Empty in this case means it has never been set, or has been reset.
But my prior uses of if the isPropertyEmpty() function have never ran into this problem when I cleared the properties... Which I am routinely doing.
Are you sure? Because that I could not explain as the behavior I described has always been the way isPropertyEmpty() works.

nwelte1
Giant
Posts: 151
Joined: Mon Nov 19, 2007 10:52 pm

Re: MapTool 1.3 Development Build 49

Post by nwelte1 »

Craig wrote:
nwelte1 wrote:
Craig wrote:
Empty in this case means it has never been set, or has been reset.
But my prior uses of if the isPropertyEmpty() function have never ran into this problem when I cleared the properties... Which I am routinely doing.
Are you sure? Because that I could not explain as the behavior I described has always been the way isPropertyEmpty() works.
Yes I am sure. I just tested this macro.

Code: Select all

<!--- Set Property with String Properties if empty--->
[h, if(isPropertyEmpty("Modifiers")):Modifiers="Str=0; Con=0; Dex=0; Int=0; Wis=0; Cha=0;"]
<!--- Set individual sting properties--->
[h: Modifiers = setStrProp(Modifiers, "Str",
  if( Strength == "",0, 
    if( Strength ==1,-4, 
      if( Strength <=3,-3, 
        if( Strength <=5,-2, 
          if( Strength <=8,-1, 
            if( Strength <=12,0, 
              if( Strength <=15,1, 
                if( Strength <=17,2,
                    floor(( Strength -12)/2) )
                )
              )
            )
          )
        )
      )
    )
  )]
[h: Modifiers = setStrProp(Modifiers, "Dex",
  if( Dexterity== "",0, 
    if( Dexterity ==1,-4, 
      if( Dexterity <=3,-3, 
        if( Dexterity <=5,-2, 
          if( Dexterity <=8,-1, 
            if( Dexterity <=12,0, 
              if( Dexterity <=15,1, 
                if( Dexterity <=17,2,
                    floor(( Dexterity -12)/2) )
                )
              )
            )
          )
        )
      )
    )
  )]
[h: Modifiers = setStrProp(Modifiers, "Con",
  if( Constitution == "",0, 
    if( Constitution ==1,-4, 
      if( Constitution <=3,-3, 
        if( Constitution <=5,-2, 
          if( Constitution <=8,-1, 
            if( Constitution <=12,0, 
              if( Constitution <=15,1, 
                if( Constitution <=17,2,
                    floor(( Constitution -12)/2) )
                )
              )
            )
          )
        )
      )
    )
  )]
[h: Modifiers = setStrProp(Modifiers, "Int",
  if( Intelligence == "",0, 
    if( Intelligence ==1,-4, 
      if( Intelligence <=3,-3, 
        if( Intelligence <=5,-2, 
          if( Intelligence <=8,-1, 
            if( Intelligence <=12,0, 
              if( Intelligence <=15,1, 
                if( Intelligence <=17,2,
                    floor(( Intelligence -12)/2) )
                )
              )
            )
          )
        )
      )
    )
  )]
[h: Modifiers = setStrProp(Modifiers, "Wis",
  if( Wisdom == "",0, 
    if( Wisdom ==1,-4, 
      if( Wisdom <=3,-3, 
        if( Wisdom <=5,-2, 
          if( Wisdom <=8,-1, 
            if( Wisdom <=12,0, 
              if( Wisdom <=15,1, 
                if( Wisdom <=17,2,
                    floor(( Wisdom -12)/2) )
                )
              )
            )
          )
        )
      )
    )
  )]
[h: Modifiers = setStrProp(Modifiers, "Cha",
  if( Charisma == "",0, 
    if( Charisma ==1,-4, 
      if( Charisma <=3,-3, 
        if( Charisma <=5,-2, 
          if( Charisma <=8,-1, 
            if( Charisma <=12,0, 
              if( Charisma <=15,1, 
                if( Charisma <=17,2,
                    floor(( Charisma -12)/2) )
                )
              )
            )
          )
        )
      )
    )
  )]
The macro filled the property, I cleared the property, and ran it again. The macro refilled it. I never ran a reset function. Heck, I did not know there was one....

Please excuse my code if it is not elegant... I have no idea was constitutes clean coding practices.

Craig
Great Wyrm
Posts: 2107
Joined: Sun Jun 22, 2008 7:53 pm
Location: Melbourne, Australia

Re: MapTool 1.3 Development Build 49

Post by Craig »

nwelte1 wrote: Yes I am sure. I just tested this macro.

Code: Select all

<!--- Set Property with String Properties if empty--->
[h, if(isPropertyEmpty("Modifiers")):Modifiers="Str=0; Con=0; Dex=0; Int=0; Wis=0; Cha=0;"]
...
Ahh I see what it is now, after running the above code Modifiers will equal "Str=0; Con=0; Dex=0; Int=0; Wis=0; Cha=0;" if it has never been set before (or has been reset), if it has and been cleared it will not be effected (so it would still be "").

The reason that the rest of your code works is set the properties in the string in the latter ifs.

If you run these two commands

Code: Select all

[setStrProp("Str=0", 1)]
[setStrProp("", 1)]
You will get the same result (i.e. Str=1; )

So while the original test/set was not working as you expect, it did not need to for the rest of the code to produce the correct result. You can try it by removing the line

Code: Select all

[h, if(isPropertyEmpty("Modifiers")):Modifiers="Str=0; Con=0; Dex=0; Int=0; Wis=0; Cha=0;"]
Clearing out the property and running it, of course if the property was never set you would be prompted for it though.

Post Reply

Return to “Announcements”