input() and other new b42 macro functions

Doc requests, organization, and submissions

Moderators: dorpond, trevor, Azhrei

User avatar
Sir Flak
Dragon
Posts: 344
Joined: Thu Sep 28, 2006 4:20 pm
Location: Oklahoma, US

Post by Sir Flak »

lols i figured it out just as you posted. I didn't realize there were different quotes.

User avatar
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Post by jfrazierjr »

BigO wrote:
Sir Flak wrote:I'm having trouble getting the input function to work

Code: Select all

[input(“MiscAttMod”,”MiscDamMod”,”MiscSavMod”)]
doesn't work for me. It puts out:

Code: Select all

Could not execute the command: line 1:7: unexpected char: 0x93
Anything wrong that you can see?
You have the wrong kind of quotes there. You need to use " not “ and ”.
Yes... Microsoft's "smart quotes" are a horrible pain in the donkey. Please, don't ever write a web site with a Microsoft product unless you feel like looking like an idiot to anyone on a Mac or Linux machine. (note, this is not a personal attack on you, just a statement of opinion based on years of hell dealing with Microsoft's of use of character codes that are supposed to be "reserved according the the International Standards Organization)
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.

Get your Dropbox 2GB via my referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..

knizia.fan
Giant
Posts: 197
Joined: Wed Jul 30, 2008 3:43 pm

Post by knizia.fan »

Tacomannerism wrote:I tried out the re-created settings file and no exceptions were raised, so that seemed to correct the file format.
Thank you for checking this. I've updated the link in the original post.

knizia.fan
Giant
Posts: 197
Joined: Wed Jul 30, 2008 3:43 pm

Post by knizia.fan »

PyroMancer2k wrote:Anyhow since it seems we are going for the fewest possible Variables I took your weapon edit code and modified it so that it only uses 2 Variables. The Description one which is default on tokens :) And WeaponC.
Your idea definitely cuts down on the clutter in the Edit Token dialog box, which is nice. However, you should be aware of a few disadvantages to squeezing things down this far.
  • Your macro code gets much bigger, because you can't rely on the PROPS inputType to magically do the work for you.
  • The token property is so big that it can't really be edited manually anymore.
  • Someday, we might have a database (a MapTool table?) of weapons, with a property string setting the default values of each weapon in the game. If we have a separate token property for each weapon we use, it would be easy to just copy the property string into the token property.
None of those are killer issues, but you should be aware. I chose one property for each weapon because each weapon is conceptually a single object. The old way of having a separate property for each weapon attribute doesn't match the mental model a user has. However, squishing all the weapons into a single property also doesn't match the conceptual model. (Using a single property does clean up the property list dramatically, though.)

PyroMancer2k wrote:How come the <!-- --> sections seem to close off when I post them?
You need to check the "Disable HTML in this post" option whenever you write a post that contains HTML tags, even in a code block. I recommend making this the default, which you can do in your forum profile.

knizia.fan
Giant
Posts: 197
Joined: Wed Jul 30, 2008 3:43 pm

Post by knizia.fan »

Mithrus wrote:Thanks so much for new functionality! Lists and hashes/assoc arrays are SO useful, and especially the input() function.

That being said, I think there is a bug in varsFromStrProp(). I was expecting it to overwrite any previous variable with what was in the hash, but it doesn't seem to do that. Macros in general are seeming VERY buggy atm, so it could just be something else, but trying to use the following code and nothing happens:

(this is the starting value)
AttrCur="Intelligence=1 ; Strength=1 ; Presence=2 ; Wits=4 ; Dexterity=4 ; Manipulation=2 ; Resolve=2 ; Stamina=3 ; Composure=2 ; "

(I do some stuff that calculates Str/Dex/Sta/Man)

Before: [Strength] [Dexterity] [Stamina] [Manipulation]

[h: AttrCur=setStrProp(eval("AttrCur"), "Strength", Str)]
[h: AttrCur=setStrProp(eval("AttrCur"), "Dexterity", Dex)]
[h: AttrCur=setStrProp(eval("AttrCur"), "Stamina", Sta)]
[h: AttrCur=setStrProp(eval("AttrCur"), "Manipulation", Man)]

[AttrCur]
[h: varsFromStrProp(AttrCur)]

After: [Strength] [Dexterity] [Stamina] [Manipulation]

AttrCur shows the updated values, but the "After" values are the same as the "Before". Any ideas? I'll post the whole macro if needed.
I just tried the following in b43

Code: Select all

[h: a=3] a is: [a]
<br>Now we set vars from [props = "a=alien; b=bob"]
<br>[h: varsFromStrProp(props)] a is now: [a]
The resulting output was
Output wrote:a is: 3
Now we set vars from a=alien; b=bob
a is now: alien
So it seems to be working, as far as I can tell. Can you construct a small, complete example which shows the problem you're talking about?

Also, in your code above, note that saying eval("AttrCur") is exactly the same as just saying AttrCur, as far as I know.

knizia.fan
Giant
Posts: 197
Joined: Wed Jul 30, 2008 3:43 pm

Post by knizia.fan »

PyroMancer2k wrote:I'll admit it was a good exercise in learning the new code. Here it is if you know how to streamline it more that would be nice ;).
There are a couple of things that can be simplified.
PyroMancer2k wrote:This Macro Sets Up Description Variable for use.

Code: Select all

[H:Description=setStrProp(Description, "DefaultWpn", "1")]
[H:c(9,""): Description=setStrProp(Description, eval('"Name" + roll.count'), "Unarmed")]
[H:c(9,""): Description=setStrProp(Description, eval('"AttackBonus" + roll.count'), 0)]
[H:c(9,""): Description=setStrProp(Description, eval('"Damage" + roll.count'), "1d4")]
[H:c(9,""): Description=setStrProp(Description, eval('"MaxDamage" + roll.count'), 4)]
[H:c(9,""): Description=setStrProp(Description, eval('"Crit" + roll.count'), "1d6")]
[H:c(9,""): Description=setStrProp(Description, eval('"Keyword" + roll.count'), "")]
Note that expressions like eval(' "Keyword" + roll.count ') can be simplified to just "Keyword" + roll.count.
PyroMancer2k wrote:This is modified K.fan code to store weapon in 1 Variable. WeaponC Variable is more of a temp holder.

Code: Select all

<Obtain>
  [H: WpnProps = "Name" + WpnNum + "=" + getStrProp(Description, eval('"Name" + WpnNum')) + "; AttackBonus" + WpnNum + "=" + getStrProp(Description, eval('"AttackBonus" + WpnNum')) +"; Damage" + WpnNum + "=" + getStrProp(Description, eval('"Damage" + WpnNum')) +"; MaxDamage" + WpnNum + "=" + getStrProp(Description, eval('"MaxDamage" + WpnNum')) +"; Crit" + WpnNum + "=" + getStrProp(Description, eval('"Crit" + WpnNum')) +"; Keyword" + WpnNum + "=" + getStrProp(Description, eval('"Keyword" + WpnNum')) +";"]


[H:Description=setStrProp(Description, eval('"Name" + WpnNum'), getStrProp(WeaponC, eval('"Name" + WpnNum')))]
[H:Description=setStrProp(Description, eval('"AttackBonus" + WpnNum'), getStrProp(WeaponC, eval('"AttackBonus" + WpnNum')))]
[H:Description=setStrProp(Description, eval('"Damage" + WpnNum'), getStrProp(WeaponC, eval('"Damage" + WpnNum')))]
[H:Description=setStrProp(Description, eval('"MaxDamage" + WpnNum'), getStrProp(WeaponC, eval('"MaxDamage" + WpnNum')))]
[H:Description=setStrProp(Description, eval('"Crit" + WpnNum'), getStrProp(WeaponC, eval('"Crit" + WpnNum')))]
[H:Description=setStrProp(Description, eval('"Keyword" + WpnNum'), getStrProp(WeaponC, eval('"Keyword" + WpnNum')))]
The list-processing functions can help with repetitive code like this. Also, the setStrProp() function will add a new string property if the key is not present, so you don't have to manually assemble the property string. (I haven't tested this code, but I believe it is equivalent to your code above.)

Code: Select all

[h: Keys = "Name, AttackBonus, Damage, MaxDamage, Crit, Keyword"]
[h: NumKeys = listCount(Keys)]
[h: WpnProps = ""]
[h,c(NumKeys, ""): WpnProps = setStrProp(
  WpnProps, 
  listGet(Keys, roll.count-1) + WpnNum, 
  getStrProp(Description, listGet(Keys, roll.count-1) + WpnNum)
)]

[h:c(NumKeys, ""): Description = setStrProp(
  Description, 
  listGet(Keys, roll.count-1) + WpnNum, 
  getStrProp(WeaponC, listGet(Keys, roll.count-1) + WpnNum)
)]

knizia.fan
Giant
Posts: 197
Joined: Wed Jul 30, 2008 3:43 pm

Post by knizia.fan »

Sir Flak wrote:Wierd guess maybe i should use note pad??
If you use Windows, I recommend using one of the programmer's editors out there. NotePad++ and EditPad Lite are two that come to mind. If you're old-school, vim or emacs are of course possible too. I'm currently using Notepad++, and the HTML syntax coloring is nice for some of the macros that I write.

User avatar
BigO
Dragon
Posts: 558
Joined: Mon Jul 28, 2008 12:23 pm
Location: Oshkosh, WI
Contact:

Post by BigO »

knizia.fan wrote:
Sir Flak wrote:Wierd guess maybe i should use note pad??
If you use Windows, I recommend using one of the programmer's editors out there. NotePad++ and EditPad Lite are two that come to mind. If you're old-school, vim or emacs are of course possible too. I'm currently using Notepad++, and the HTML syntax coloring is nice for some of the macros that I write.
I'll second the vote for NotePad++. I use it on windows for stuff like this, and I like it a lot. I use TextWrangler (also free) when on the Mac writing macros. In both cases I find the most accurate syntax highlighting to be setting it to html mode. Works great.
--O

I am a small and fragile flower.
http://maptool.rocks.andyousuck.com

DeviantNull
Dragon
Posts: 685
Joined: Wed Sep 03, 2008 12:34 pm
Location: The Junkyard

Post by DeviantNull »

I've been playing around with this for a couple of hours now... thank you so much! I managed to throw together a 4e d20 roller that does stats/skills/init/saves and a plain ol' d20 roll with one simple macro. I love it!

I've got a lot of rebuilding to do, but it's oh so worth it.

User avatar
PyroMancer2k
Dragon
Posts: 925
Joined: Thu Sep 11, 2008 2:04 pm

Post by PyroMancer2k »

knizia.fan wrote:
PyroMancer2k wrote:Anyhow since it seems we are going for the fewest possible Variables I took your weapon edit code and modified it so that it only uses 2 Variables. The Description one which is default on tokens :) And WeaponC.
Your idea definitely cuts down on the clutter in the Edit Token dialog box, which is nice. However, you should be aware of a few disadvantages to squeezing things down this far.
  • Your macro code gets much bigger, because you can't rely on the PROPS inputType to magically do the work for you.
  • The token property is so big that it can't really be edited manually anymore.
  • Someday, we might have a database (a MapTool table?) of weapons, with a property string setting the default values of each weapon in the game. If we have a separate token property for each weapon we use, it would be easy to just copy the property string into the token property.
None of those are killer issues, but you should be aware. I chose one property for each weapon because each weapon is conceptually a single object. The old way of having a separate property for each weapon attribute doesn't match the mental model a user has. However, squishing all the weapons into a single property also doesn't match the conceptual model. (Using a single property does clean up the property list dramatically, though.)
Yea I realize that it was a lot more work just doing the first one. Though I thought in part the reason for the pop up menu was so that you didn't need to manually edit the variable. But I think if anything a nice multi-lined window like one for macros would be nice when editing variables.

I was even considering taking it a step further in having it hold all the skills since like in 4.0 they take up 17 variables already assuming you put all their bonuses and such in a single variable. It's going to be a bit tricky on how to do it though.

Lindharin
Dragon
Posts: 668
Joined: Sat Apr 21, 2007 4:51 pm

Post by Lindharin »

DeviantNull wrote:I've been playing around with this for a couple of hours now... thank you so much! I managed to throw together a 4e d20 roller that does stats/skills/init/saves and a plain ol' d20 roll with one simple macro. I love it!
Would you be willing to post it?

User avatar
lmarkus001
Great Wyrm
Posts: 1867
Joined: Sat Mar 29, 2008 12:30 am
Location: Layfayette Hill, PA

Post by lmarkus001 »

These additions are wonderful!

I have just completed my first cut on a "generic" D&D3.5 Attack macro (phew). I will follow up with a detailed post of what I did, but here is what I cover:
  • * Up to 9 distinct attacks (worst case I could identify was 7 - Marilith Demon with 6 different weapons and a tail)
    * Primary vs. Secondary vs. 2 Handed vs. Two-Weapon attacks (both attack mods and STR mods)
    * Weapon Finesse
    * STR bows
    * Multiple tentacles
    * Decaying attacks for BAB > 5 (multiple attacks per round)
    * Special damage like flaming sword
    * Criticals (and crit multipliers 2,3,4)
    * Special damage criticals (Burst weapons)
I have to say that this has been made far more organized by your code additions!

Thread to my macro: http://forums.rptools.net/viewtopic.php?p=63907
Last edited by lmarkus001 on Wed Sep 17, 2008 11:15 am, edited 1 time in total.

DeviantNull
Dragon
Posts: 685
Joined: Wed Sep 03, 2008 12:34 pm
Location: The Junkyard

Post by DeviantNull »

Lindharin wrote:Would you be willing to post it?
Sure, though it's not exactly pretty or sophisticated... I don't want to clutter up this thread, whats a good sub-fora for that sort of stuff? Regular Maptools? User creations?

knizia.fan
Giant
Posts: 197
Joined: Wed Jul 30, 2008 3:43 pm

Post by knizia.fan »

PyroMancer2k wrote:I was even considering taking it a step further in having it hold all the skills since like in 4.0 they take up 17 variables already assuming you put all their bonuses and such in a single variable. It's going to be a bit tricky on how to do it though.
Here's a quick attempt at a set of unified skill check macros for 4E D&D. It assumes a Skills property defined as:

Code: Select all

Skills: Acrobatics=0 ; Arcana=0 ; Athletics=0 ; Bluff=0 ; Diplomacy=0 ; Dungeoneering=0 ; Endurance=0 ; Heal=0 ; History=0 ; Insight=0 ; Intimidate=0 ; Nature=0 ; Perception=0 ; Religion=0 ; Stealth=0 ; Streetwise=0 ; Thievery=0 ;
(The macros also use a Private property for persistent settings, as usual.)

First, the "Set Skills" macro, which lets you adjust the bonuses for your character. This is where you enter training, feat, and other permanent bonuses.

Code: Select all

<!-- SET SKILLS MACRO -->

[h: success = input(
  "foo | Don't add bonuses from abilities or level here. | Note | LABEL",
  "Skills | " + Skills + " | Set skill bonuses | PROPS"
)]
[h: abort(success)]
The macro displays the following dialog box:
Image


Then we have the "Skill Check" macro. It auto-adds the level bonus, ability bonus, and armor check penalty as appropriate.

Code: Select all

<!-- SKILL CHECK MACRO -->

<!-- This macro assumes that the Skills property contains 
  -- all permanent bonuses other than level and ability. -->

<!-- Some reference lists -->
  [h: SkillNames = "Acrobatics, Arcana, Athletics, Bluff, Diplomacy, Dungeoneering, Endurance, Heal, History, Insight, Intimidate, Nature, Perception, Religion, Stealth, Streetwise, Thievery"]
  [h: SkillAbils = "Dex, Int, Str, Cha, Cha, Wis, Con, Wis, Int, Wis, Cha, Wis, Wis, Int, Dex, Cha, Dex"]
  [h: ArmorCheckAbils = "Str, Con, Dex"]
  [h: NumSkills = listCount(SkillNames)]

<!-- Compute the total bonus for each skill -->
  [h: SkillBonuses = Skills]
  [h,c(NumSkills,""): SkillBonuses = setStrProp(
    SkillBonuses, 
    listGet(SkillNames, roll.count-1), 
    getStrProp(Skills, listGet(SkillNames, roll.count-1)) 
      + LevelBonus
      + eval(listGet(SkillAbils,roll.count-1)+"Bonus") 
      + if(listFind(ArmorCheckAbils, listGet(SkillAbils,roll.count-1)) != -1, ArmorCheckPenalty, 0)
  )]

<!-- Construct the string for the listbox -->
  [h: SkillStr = SkillNames]
  [h,c(NumSkills,""): SkillStr = listReplace(
    SkillStr, 
    roll.count-1, 
    listGet(SkillNames, roll.count-1) 
      + " (" 
      + if(getStrProp(SkillBonuses, listGet(SkillNames,roll.count-1)) < 0, "", "+")
      + getStrProp(SkillBonuses, listGet(SkillNames,roll.count-1))
      + ")"
  )]

<!-- Display the dialog box, selecting the skill that was chosen last time -->
  [h: success = input(
    "SkillNum | " + SkillStr + " | Select a skill | LIST | SELECT=" + getStrProp(Private, "LastSkill", 0),
    "TempBonus | 0 | Temporary bonus"
  )]
  [h: abort(success)]

<!-- Make the roll -->
<!-- doesn't work in b43, will in b44  [h: SkillBonus = indexValueStrProp(SkillBonuses, SkillNum)] -->
  [h: SkillBonus = getStrProp(SkillBonuses, listGet(SkillNames, SkillNum))]
  <b>{listGet(SkillNames, SkillNum)} check:</b> [1d20 + SkillBonus + TempBonus]
  
<!-- Save the selected skill for next time -->
  [h: Private = setStrProp(Private, "LastSkill", SkillNum)]
You get the following dialog, which includes the net skill check bonus in the list for your verification. It remembers the last skill you used.
Image

knizia.fan
Giant
Posts: 197
Joined: Wed Jul 30, 2008 3:43 pm

Post by knizia.fan »

DeviantNull wrote:
Lindharin wrote:Would you be willing to post it?
Sure, though it's not exactly pretty or sophisticated... I don't want to clutter up this thread, whats a good sub-fora for that sort of stuff? Regular Maptools? User creations?
User creations is probably best. If you don't mind sharing a thread with others, you could start a thread titled "Post your macros that use the new b43 features". Having a single thread is probably good so people can share/steal ideas from each other.

Post Reply

Return to “Documentation Requests/Discussion”