Character Sheet Not Updating & Unexpected Error - Solved

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
User avatar
Oriet
Cave Troll
Posts: 34
Joined: Mon Dec 05, 2011 10:58 am
Location: Somewhere that's not there, but not really here.
Contact:

Character Sheet Not Updating & Unexpected Error - Solved

Post by Oriet »

So I've been doing even more with MapTool, expanding what game systems I'm using it for. I've got a half-complete interactive character sheet macro set for my custom d20 Star Wars and a fully functional interactive character macro set for Dark Heresy (and I have come to realise I hate their abundance of skills, even in just the core rulebook). Using those as a base I started making an interactive character sheet for a game I'm developing, which is using the working title of Simple RPG, as I wish to test the mechanics out in MapTool to work out bugs (and later use it for a campaign).

I've been able to get it to display the properties correctly, but I can't get it to reliably update any of them. At first it was just simple macro errors from typos (which got fixed), incorrect roll options (which might have been fixed, as it no longer gives those errors), and then from me not remembering that html checked inputs don't pass on unchecked variables. I've since changed those to radio options, because following the guide on using json.contains was not working for some reason (mostly likely user error). I was almost at the point of scrapping the whole macro set and making one from the ground up, but then I ran into this error:
Error
java.lang.ArrayIndexOutOfBoundsException: 0
at net.rptools.maptool.client.ui.htmlframe.HTMLPaneFormView.submitData(HTMLPaneFormView.java:120)
at javax.swing.text.html.FormView.actionPerformed(FormView.java:356)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6288)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6053)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4651)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4481)
at com.jidesoft.docking.b.a(Unknown Source)
at com.jidesoft.docking.DefaultDockingManager.handleEvent(Unknown Source)
at com.jidesoft.docking.DefaultDockingManager$46.eventDispatched(Unknown Source)
at java.awt.Toolkit$SelectiveAWTEventListener.eventDispatched(Toolkit.java:2366)
at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Toolkit.java:2258)
at java.awt.Toolkit.notifyAWTEventListeners(Toolkit.java:2216)
at java.awt.Component.dispatchEventImpl(Component.java:4549)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4481)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1850)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:901)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:513)
at java.awt.Component.dispatchEventImpl(Component.java:4523)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4481)
at sun.awt.X11.XWindow$1.run(XWindow.java:380)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
at net.rptools.maptool.client.swing.MapToolEventQueue.dispatchEvent(MapToolEventQueue.java:38)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
I already tried restarting MapTool and Java, as well as restarting my computer to see if it would clear it up, but it hasn't. Because there's currently very little done for the game, here's the properties and macros in case I really did make something completely fubar.
Campaign Properties

Code: Select all

«Displayed»
*@Health:{currentWounds} / {maxWounds}
*@Move:{agility + 0}
*@Armour:{armourType} ({armourResist})
*@Weapon_1:{weapon1}{ammo1}
*@Weapon_2:{weapon2}{ammo2}
«Statistics»
strength:5
vitality:5
dexterity:5
agility:5
intellect:5
resolve:5
health.woundMultiplier:4
maxWounds:{(vitality * health.woundMultiplier) + 0}
currentWounds:{maxWounds}
fatigue:0
«Equipment»
armourType:clothes
armourResist:0
weapon1
weapon2
ammo1
ammo1current
ammo2
ammo2current
«Skills»
skills.MeleeFighting:base=0 ; edged=0 ; blunt=0 ; polearms=0 ; flexible=0 ; thrown=0 ;
skills.RangedFighting:base=0 ; archery=0 ; projectiles=0 ; rayguns=0 ; missiles=0 ; artillery=0 ;
skills.basic:Acrobatics=0 ; Athletics=0 ; Awareness=0 ; Disguise=0 ; Dodge=0 ; Drive=0 ; Endurance=0 ; FirstAid=0 ; Legerdemain=0 ; Navigation=0 ; Persuasion=0 ; Pilot=0 ; Search=0 ; Security=0 ; Stealth=0 ; Survival=0 ; Teaching=0 ; Wrangling=0 ;
skills.trained:Accounting=0 ; Astrogeology=0 ; Biology=0 ; Chemistry=0 ; Cryptography=0 ; Culture=0 ; Demolitions=0 ; Electronics=0 ; History=0 ; Law=0 ; Mechanics=0 ; Medicine=0 ; Physics=0 ; PopularCulture=0 ; Programming=0 ; Psychology=0 ; Surgery=0 ; Tactics=0 ;
openCharacterSheet

Code: Select all

[h: link = macroLinkText("openCharacterSheet@Lib:token", "none")]
[frame("CharacterSheet"): {
    <html>
    <head>
        <link rel="onChangeSelection" type="macro" href="[r:link]">
        <link rel="stylesheet" type="text/css" href="css@Lib:token"></link>
    </head>
    <body>
        [r, macro("characterSheet@Lib:token"): getSelected()]
    </body>
    </html>
}]  
Does as it's named.
css

Code: Select all

.odd { background-color: #FFFFFF }
.even { background-color: #EEEEAA }
th { background-color: #113311; color: #FFFFFF }         
Styling for the sheet.
characterSheet
Displays the token's properties and has input fields.
editCharacterSheet

Code: Select all

[h: arguments = json.toStrProp(macro.args)]
[h: varsFromStrProp(arguments)]
[h: id = json.get(macro.args, "id")]

<!-- set primary attributes -->
[h: attributes = "Strength, Vitality, Dexterity, Agility, Intellect, Resolve"]
[h,foreach(attrib, attributes),code: {
    [r: setProperty(attrib, attrib, id)]
}]

<!-- set skills -->
[h: base = json.get(macro.args, "MeleeFighting")]
[h,if(! json.contains(arguments, "edged")): edged = 0]
[h,if(! json.contains(arguments, "blunt")): blunt = 0]
[h,if(! json.contains(arguments, "polearms")): polearms = 0]
[h,if(! json.contains(arguments, "flexible")): flexible = 0]
[h,if(! json.contains(arguments, "thrown")): thrown = 0]
[h: skillset = strPropFromVars("base, edged, blunt, polearms, flexible, thrown", "unsuffixed")]
[h: setProperty("skills.meleeFighting", skillset, id)]

[h: base = json.get(macro.args, "RangedFighting")]
[h,if(! json.contains(arguments, "archery")): archery = 0]
[h,if(! json.contains(arguments, "projectiles")): projectiles = 0]
[h,if(! json.contains(arguments, "rayguns")): rayguns = 0]
[h,if(! json.contains(arguments, "missiles")): missiles = 0]
[h,if(! json.contains(arguments, "artillery")): artillery = 0]
[h: skillset = strPropFromVars("base, archery, projectiles, rayguns, missiles, artillery", "unsuffixed")]
[h: setProperty("skills.rangedFighting", skillset, id)]

[h: skillset = strPropFromVars("Acrobatics, Athletics, Awareness, Disguise, Dodge, Drive, Endurance, FirstAid, Legerdemain, Navigation, Persuasion, Pilot, Search, Security, Stealth, Survival, Teaching, Wrangling", "unsuffixed")]
[h: setProperty("skills.basic", skillset, id)]

[h: skillset = strPropFromVars("Accounting, Astrogeology, Biology, Chemistry, Cryptography, Culture, Demolitions, Electronics, History, Law, Mechanics, Medicine, Physics, PopularCulture, Programming, Psychology, Surgery, Tactics", "unsuffixed")]
[h: setProperty("skills.trained", skillset, id)]


Changes saved to [r: getName(id)].
[h, macro("openCharacterSheet@Lib:token"): id]  
Is supposed to update the token's properties, but only changes the Attributes (and it took a while to even do that, as simple as that part is) but now returns the above listed error.

I'm really at my wits end over this, and am feeling like I won't be able to progress further in coding macros. I'd love to be able to do more with macros (and perhaps eventually full on programming), but running into problems that make me feel like a two-bit n00b script-kiddy is getting disheartening. (This is also not the only macro/macro-set giving me issues, though it is having more problems than others which I've been able to kludge into some form of functionality.)

...

Alright, I have no clue why it doesn't like me posting in the code for the characterSheet macro itself, and I've tried numerous times to get it in the post. As such I've attached the campaign file that has all of that in it.
Attachments
SimpleRPGv0.2.03.cmpgn
SimpleRPGv0.2.03 campaign file
(230.68 KiB) Downloaded 31 times
Last edited by Oriet on Fri Dec 23, 2011 2:53 pm, edited 1 time in total.
Kill them all, and let the Game Master grant the exp!

Image

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: Character Sheet Not Updating & Unexpected Error

Post by CoveredInFish »

Hmm ... I had a 30min-look into your code and I dont have a clue whats going on. I dont see any obvious cause for that (confirmed) error.
I replaced the form handler with some simple debug dump, I removed the guillemets from the campaign props and the exception still gets thrown.

:?

username
Dragon
Posts: 277
Joined: Sun Sep 04, 2011 7:01 am

Re: Character Sheet Not Updating & Unexpected Error

Post by username »

I have virtually no experience with macros, but to me it seems that something is wrong with this code

Code: Select all

[h: setProperty("skills.meleeFighting", skillset, id)]
Maybe the quotes are wrong, the prefix or whatever. However the string that the backend gets to parse is

Code: Select all

id=7F0001012DAAC2063906000006000001&Strength=5&Vitality=6&Dexterity=6&Agility=6&Intellect=5&Resolve=5&0=0&Edged=0&Blunt=0&Polearms=0...
Please see the "0=0" above. (The ellipses are mine.) From then on havoc ensues. Later this is seen

Code: Select all

Intellect=Intellect&Resolve=Resolve&=&Edged=0...
Note the "&=&" and that breaks things finally.
Everything between "&" and "&" should be name=value pairs.

User avatar
metatheurgist
Dragon
Posts: 363
Joined: Mon Oct 26, 2009 5:51 am

Re: Character Sheet Not Updating & Unexpected Error

Post by metatheurgist »

In your character sheet you have "MeleeFighting" and "RangedFighting" as inputs but these aren't used to reset the "base" variable in the respective properties. That's causing the error.

While you say that the attributes are being set I can't see how it would work as is. I would think that this is required:

Code: Select all

[r: setProperty(attrib, eval(attrib), id)]
The problem with html form variables not being passed as I understand it, only applies to checkboxes, not radios. You don't need:

Code: Select all

[h,if(! json.contains(arguments, "edged")): edged = 0]
[h,if(! json.contains(arguments, "blunt")): blunt = 0]
[h,if(! json.contains(arguments, "polearms")): polearms = 0]
[h,if(! json.contains(arguments, "flexible")): flexible = 0]
[h,if(! json.contains(arguments, "thrown")): thrown = 0]
That's always setting them to 0.

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Character Sheet Not Updating & Unexpected Error

Post by aliasmask »

I think username pointed out some major errors. My guess is you're using the & as a delimiter so you can parse through and replace values. I suggest using | because & in front of certain characters has special meaning and could alter your output. Also use of « » in your token type properties could cause problems. Generally, if you want a visual break in your properties, make the name a valid variable name like "Display_________________". Depending on what you're doing with the variables, it may not be an issue to use non-valid variable names as the token property name.

username
Dragon
Posts: 277
Joined: Sun Sep 04, 2011 7:01 am

Re: Character Sheet Not Updating & Unexpected Error

Post by username »

aliasmask wrote:I think username pointed out some major errors. My guess is you're using the & as a delimiter so you can parse through and replace values. I suggest using | because & in front of certain characters has special meaning and could alter your output. Also use of « » in your token type properties could cause problems. Generally, if you want a visual break in your properties, make the name a valid variable name like "Display_________________". Depending on what you're doing with the variables, it may not be an issue to use non-valid variable names as the token property name.
The "&" in the string I quoted are alright and relate to the GET request that is apparently sent to the backend for evaluation. There are no special characters I have seen that would cause such a problem. I have the feeling that something is wrong with quotes somewhere. It looks like "0=0" should be "someVar=0", but "someVar" was evaluated to soon, maybe "skills.meleeFighting".

User avatar
Oriet
Cave Troll
Posts: 34
Joined: Mon Dec 05, 2011 10:58 am
Location: Somewhere that's not there, but not really here.
Contact:

Re: Character Sheet Not Updating & Unexpected Error

Post by Oriet »

Thanks for the responses! I'll give it a thorough look over again tomorrow, keeping an eye out for everything that was mentioned. I'll also replace the guillemets (never knew they were called that) with something else; currently they're in there to label areas of like properties on the token when referencing it, but I could easily replace it with something easier to parse/less likely to cause issue since I don't plan on those being variables at all. I had thought of using bullets (•), but if I recall correctly MapTool doesn't always parse it properly, as is the case for many other glyphs I thought of using. Such is a limitation of being on a unicode based OS with a cross-compatible program that doesn't use it. Underscores should work fine then, as I also wanted to avoid operators and other glyphs that would be read wrong.

Most definitely have to track down why it's doing 0=0 and what is most likely ""="". If I still can't get it working I'll probably try rewriting it while using the broken code as a guide, and also making sure to add in comments (using the format of [r: "<!-- stuff -->"]) to help make sure I know exactly what I'm doing where.

As a side note, writing macros has been really helping me with touch-typing numbers (without relying on the number pad) and special characters, and while I'm still looking a the keyboard half the time for it, I'm at least not having to look every time or move my hands completely away from the home-row for it. *Is trying to look on the bright side of things since she also just had a change in medication.*

[ETA] Oh, and I've just been using commas for string lists and semicolons for strings of key-value pairs, as not only is that what I've learnt to use for them it also means less typing as I don't have to specify what I'm using in the different functions.
Kill them all, and let the Game Master grant the exp!

Image

User avatar
Oriet
Cave Troll
Posts: 34
Joined: Mon Dec 05, 2011 10:58 am
Location: Somewhere that's not there, but not really here.
Contact:

Re: Character Sheet Not Updating & Unexpected Error

Post by Oriet »

Alright, haven't had much time to look over it yet today, but I've already noticed a few things.

I've tracked down where the 0=0 is coming from, but I still don't know why it's giving that output. It should be "base=#", with base having the value from the MeleeFighting variable that was passed from the calling macro. The equals without a key-value pair is also supposed to be that variable and value, so it's somehow being set to 0 and/or a null set before it tries to set the property. I can definitely see why a null set doesn't work as a variable, but I don't know why it's loosing the variable name.

The [h,if(! json.contains(arguments, "edged")): edged = 0] lines are probably deprecated then, as I hadn't removed them when I changed it from check boxes to radio buttons, and were there to ensure the variables had a value (so it wouldn't prompt for them) if the variable wasn't passed (as happens with unchecked check boxes).

I think the problem is coming from the MeleeFighting and RangedFighting variables in the characterSheet macro. I managed to get it so it doesn't run an error the first time you try to edit the contents of a token's character sheet, but running it again causes an error. I did find that when it tries to update the token, it is definitely setting the base variables in skills.meleeFighting and skills.rangedFighting to a null set, though I cannot figure out why.

[ETA] Oh, and apparently I was thinking of an older incarnation of the macro-set for it updating the attributes. Using eval() does seem to have fixed that. Thanks.
Kill them all, and let the Game Master grant the exp!

Image

User avatar
metatheurgist
Dragon
Posts: 363
Joined: Mon Oct 26, 2009 5:51 am

Re: Character Sheet Not Updating & Unexpected Error

Post by metatheurgist »

Uh...starting to feel like Bill Murray in a movie about a large rodent now...
metatheurgist wrote:In your character sheet you have "MeleeFighting" and "RangedFighting" as inputs but these aren't used to reset the "base" variable in the respective properties. That's causing the error.
In your character sheet you have inputs for "MeleeFighting" and "RangedFighting". You don't have any "Base" inputs. When you call the editCharacter macro it should get passed "MeleeFighting" and "RangedFighting" but not "base". However that in the character sheet the name attribute for these inputs is set to [r:MeleeFighting] and [r:RangedFighting] giving you 2 inputs with a name of "0" (the current value of MeleeFighting and RangedFighting), resulting in "0=0" being passed into your editCharacter macro instead of the base value for these skills.

In your editCharacter macro you set the properties "skill.MeleeFighting" and "skill.RangedFighting" using a variable named "base" (which doesn't exist because it was never passed to this macro from your character sheet) and strPropFromVars. You need to set the base vaiable with either "MeleeFighting" or "RangedFighting" before you try to set the "base" variable into your properties where you use strPropFromVars.

User avatar
Oriet
Cave Troll
Posts: 34
Joined: Mon Dec 05, 2011 10:58 am
Location: Somewhere that's not there, but not really here.
Contact:

Re: Character Sheet Not Updating & Unexpected Error

Post by Oriet »

I think you're missing bits of my code. Such as these two in the characterSheet macro:

Code: Select all

<tr class="odd">
            <td><b>Melee Fighting</b></td>
            [h: MeleeFighting = getStrProp(getProperty("skills.MeleeFighting", id), "base")]
            <td>[r: getProperty("Dexterity", id) + MeleeFighting]</td>
            <td><input type="text" name="[r:MeleeFighting]" value="[r: MeleeFighting]" size="3" align="right"></td>
        </tr> 

Code: Select all

<tr class="odd">
            <td><b>Ranged Fighting</b></td>
            [h: RangedFighting = getStrProp(getProperty("skills.RangedFighting", id), "base")]
            <td>[r: getProperty("Dexterity", id) + RangedFighting]</td>
            <td><input type="text" name="[r:RangedFighting]" value="[r: RangedFighting]" size="3" align="right"></td>
        </tr> 
And then these two lines in the editCharacterSheet macro:

Code: Select all

[h: base = json.get(macro.args, "MeleeFighting")] 

Code: Select all

[h: base = json.get(macro.args, "RangedFighting")] 
So, unless I'm somehow doing those wrong it should be setting the "base" key-value pair in their string properties. I have been considering renaming the "base" variable in each of them with "melee" and "ranged" appropriately, so that I don't have to worry about variables that possess the same name (though I've tried to avoid any conflict by having them use the same name in very small snippets so that there is no overlap in the code with them).

I mean, I will correct them if it's shown I did them wrong, but I did include commands to assign "base" with MeleeFighting and Ranged fighting, and then back to "base" for input in the property strings from the get go.
Kill them all, and let the Game Master grant the exp!

Image

User avatar
metatheurgist
Dragon
Posts: 363
Joined: Mon Oct 26, 2009 5:51 am

Re: Character Sheet Not Updating & Unexpected Error

Post by metatheurgist »

Code: Select all

[h: base = json.get(macro.args, "MeleeFighting")]  

Code: Select all

[h: base = json.get(macro.args, "RangedFighting")]  
Yes I did miss those, but as I pointed out:

            <td><input type="text" name="[r:MeleeFighting]" value="[r: MeleeFighting]" size="3" align="right"></td>
            <td><input type="text" name="[r:RangedFighting]" value="[r: RangedFighting]" size="3" align="right"></td>

What's that going to name the input controls and how will that affect the information passed onto editCharacter?

User avatar
Oriet
Cave Troll
Posts: 34
Joined: Mon Dec 05, 2011 10:58 am
Location: Somewhere that's not there, but not really here.
Contact:

Re: Character Sheet Not Updating & Unexpected Error

Post by Oriet »

*Looks at the listed lines.*
*Looks at them in her code.*
*Looks elsewhere in her code for similar lines.*
*Looks back at the pointed out lines.*

Ah! How did I keep missing that‽ Thank you for pointing it out (again, and again) >.<)!

*Makes the variables different so it's not being "val=val", and puts the name for the key in quotes.*
*Removes the deprecated code from when it was using check boxes.*
*Watches it work beautifully.*

By Moradin's hammer, it works!

I think taking a break from going over that bit of code (including additional sleep) combined with patient help in pointing out problems makes Captain Planet! Er, I mean, leads to good solutions.

[Aw, wish there were strike-through tags.]
Kill them all, and let the Game Master grant the exp!

Image

Post Reply

Return to “Macros”