Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Moving items from a repeating group to a slot?

I'm playing around with character sheet design, and I was trying to do something that I can't find any obvious examples of how to do; I have some quite clunky options but nothing I really like, so I'm wondering if I'm missing an obvious option. The basic idea is that I have a list of wieldable objects (weapons, tools, etc) in a repeating group, and I want to be able to select one of those items as being held in one hand or the other. This implies at least the following: When I select an item as held, it should be marked as held in inventory, and the previous object, if any, should no longer be marked. Macros and roll buttons should be able to reference properties of items based on the hand they're held in. Essentially, something like @{ @{right_hand_item_id}_name } -- but attribute expansion doesn't seem to support recursion. I could put a button on the item that triggers copying its properties into fixed properties (e.g. copy repeating_items_ID_name to right_hand_item_name and so on) but I'd rather not.
1629188427

Edited 1629189663
GiGs
Pro
Sheet Author
API Scripter
You'll need to use a sheet worker for this. You could have it work like this: Create hidden attributes outside of the repeating section to hold the properties of the selected item. When a player clicks an item to select it, the sheet worker springs into action, and copies the current properties to the hidden attributes, and unchecks any other checked boxes in the repeating section With this approach you don't need a button - it just happens seamlessly behind the scenes whenever a player selects an item. So then you could use @{right_hand_item_name} directly, because that's outside the repeating section. The tricky part is unchecking all but the selected item, for that you'll need to use the getSectionIDs function. Can you post the code for your repeating section, and state which attributes you want to access with macros, and I'll write the code for you?
Oh, I can write the code you're describing. It's just clunky (and if you edit the object, you'll have to re-click the wield button, unless I just put a listener on the entire object) so I was hoping for something better.
1629269772
GiGs
Pro
Sheet Author
API Scripter
Unfortunately that's the best we've got :) You dont have to put a listener on the entire object, just the relevant attributes.
1629278098

Edited 1629278622
Oosh
Sheet Author
API Scripter
I'm not sure how you're defining 'clunky' and 'not-clunky' - is the objective to have a dynamic <select> where the player can choose an item for each hand? Or is a checkbox in the repeating section acceptable? Rough example: Left Right     Name        Details [x]     [  ]       Shield        Is a shield, does shieldy things [  ]     [x]        Sword      Inflcits hurt [  ]    [  ]        Stick         Provides +5 Dodge if equipped The above is definitely achievable, but if you want some kind of dynamic drop-down, you might be able to experiment with the new faux-jQuery on the dev server. I believe you can add classes to an <option> element, so theoretically you can use the new functionality to toggle the visibility of each option in a <select> via toggling a class. No idea if this works - anywhere outside of Roll20 you'd just manipulate the DOM to add and remove options. If using a checkbox is an OK option, it's not overly difficult, but it might fall under the 'clunky' heading for you. Another important factor - are you planning on using the newer startRoll() functionality via action buttons, or just the old roll buttons? You can eliminate the clunk, and create some very interesting functions by combining startRoll() with asynchronous coding - if you're willing to go down that path I've done something very similar to what you're trying to achieve. I wouldn't try to turn it into synchronous code & roll buttons though - too much clunk. The best option for a synchronous version is exactly what GiGs suggested straight up - you need to copy the entire repeating section to non-repeating attributes. This can still be done with a single getAttrs & setAttrs - I'm not sure how 'clunky' I'd call it - the code is relatively straight-forward and not particularly inefficient. But maybe not 'elegant'. Happy to post examples of async versions if it helps - I've done almost the same thing as you're trying to do, except only one weapon is "readiable", not one per hand - a minor detail though. But it is all async code, and leverages the async nature of startRoll() to keep the code clean.
1629281075
GiGs
Pro
Sheet Author
API Scripter
Oosh said: The best option for a synchronous version is exactly what GiGs suggested straight up - you need to copy the entire repeating section to non-repeating attributes. It's also the best option for players creating their own macros. Accessing attributes outside of a repeating section is a lot easier, and the names can be a lot smoother too. That said, please post your async examples - I haven't had the opportunity to play with startRoll yet, and I'm keen to see worked examples more practical than the documentation.
I hadn't seen startRoll, that does look interesting (for several reasons), though I'd like to see a worked example of how it actually functions.
1629360994

Edited 1629361041
Oosh
Sheet Author
API Scripter
I'll throw something together shortly. I've been meaning to start a startRoll() thread to see what people have come up with and get ideas together for the wiki, but Life keeps thwarting me. I'm very easily thwarted.
Hm. I solved my other problems in other ways, but seems like startRoll() would be a good way of automatically tracking consumption of resources (decrement the spell slot or whatever).
1629505184
Oosh
Sheet Author
API Scripter
Whoops never got back to this - sorry. Yes - startRoll() is ideal for that. Since the action button immediately triggers your code, you can abort a roll or send a failure message if there aren't enough resources to cast the spell/fire the weapon. You can calculate whatever you want before the roll starts, during the roll, after the roll, start a second roll with your calculations, or send a new action button to chat with the results of the first roll. There's a heap of previously-API-only functionality that now works straight in a sheet. You can even put a couple of buttons on your damage templates to apply the rolled damage (or half-damage, or healing) to the currently selected token. Much like a certain other VTT :)