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

Can I use @{selected|token_name} in a macro to reference a specific data point

I am trying to use the ideas from this video

1) Attach a transparent token to a character sheet

2) Drag the character on to a city map with TokenNameNumber script.  Have the token_name either be just a number %%NUMBERED%% or City%%NUMBERED%%

3) Have a Macro for "info" or "Shopkeeper" or "notes"

4) Keep the info in a list somewhere, and then use the token_name to reference a specific piece of data?  An attribute on a character sheet (maybe the same one), a pre-determined result from a rollable table (is that a thing?), a specific card from a deck?.  

My first thought was to have a character sheet named "City" and then Attributes named 1,2,3,4 etc.  Put the "info" in the value and maybe a link to an image in the max and have it referenced @{City|@{selected|token_name}}, but I understand that doesn't work.  So, it's back to the drawing board.

Thanks for any ideas.


haha - this video : https://youtu.be/kNiwPx5V8GE

December 23 (4 years ago)

Edited December 23 (4 years ago)
Finderski
Sheet Author
Compendium Curator

If you used the character's name, you don't need the selected stuff...that's only if you don't know/don't use the character's name in the attribute call.  So, for your City example, let's say you had an attribute called Population, you'd call that like this:

@{City|Population}

or, for a more generic macro, this...

@{selected|Population}

For that second one, you'd need to select the city first, of course.

And, since you're using the name as part of your example, you could also do this:

@{selected|character_name}

That would output the character's name, in the case of your example above "City."

December 23 (4 years ago)


Michael N. said:

I am trying to use the ideas from this video

1) Attach a transparent token to a character sheet

2) Drag the character on to a city map with TokenNameNumber script.  Have the token_name either be just a number %%NUMBERED%% or City%%NUMBERED%%

3) Have a Macro for "info" or "Shopkeeper" or "notes"

4) Keep the info in a list somewhere, and then use the token_name to reference a specific piece of data?  An attribute on a character sheet (maybe the same one), a pre-determined result from a rollable table (is that a thing?), a specific card from a deck?.  

My first thought was to have a character sheet named "City" and then Attributes named 1,2,3,4 etc.  Put the "info" in the value and maybe a link to an image in the max and have it referenced @{City|@{selected|token_name}}, but I understand that doesn't work.  So, it's back to the drawing board.

Thanks for any ideas.

I'm confused about what problem you're trying to solve. 

If I'm understanding correctly, you want to create a generic "City" character that has a transparent token, and using the TokenNameNumber script to create incrementing city numbers as they are pulled from the journal.  Then you want to have different data points (such as 'Shopkeeper') that will adjust based on which specific city number has been generated, by referencing the city name (the token name of the specific city token that is clicked on)?

I'm pretty sure there are easier ways to do what you're trying to do, but it should be possible if you're set on this method, with a couple caveats.

December 23 (4 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

You have six places on a token to store and retrieve data (seven with the API): The token bubbles and the GM notes.

Store each of your attributes in a token bubble current value and max, and the most detailed one in the GM notes. The bubble values can be returned with a simple attribute call:

@{selected|bar1|current}

Note that you can only use current values in the bubbles or it will make the bars show, which is probably not desirable. So that's technically three spots. By using the "selected" keyword, you can just pop this macro into a token ability for the City character sheet and it will report correctly for any selected token.

The GM Notes can be retrieved with the API script Supernotes.

Trying to coordinate Token "City 1" with attribute "Shopkeeper 1" and so forth for every token is doable, but frighteningly tedious. I imagine a script could be written to handle it, though.

Is there a reason you want to separate all the info out so piecemeal rather than just keep it in one easily-edited spot?

the way I envisioned it was this

A character sheet named City_Info has attributes named 1,2,3,4 etc... as many as necessary for the city.  The description (or a link to a handout for more detailed info) as the value for each.  

The transparent numbered tokens would then have token actions that could call the appropriate description based on their token name. 


December 24 (4 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

I think it would be easiest to use the "selected" keyword instead of trying to piece together something that would assemble on the fly.

City character sheet has attributes:

leader
population
best_restaurant
...

Then use one set of macros, probably kept on a Macro Character Sheet that call for example:

@{selected|leader}
@{selected|population}
@{selected|best_restaurant
...

Then you only deal with one set of macros, rather than attaching a full set of abilities to each sheet. Then if you want to tinker with the formatting a bit (like putting the output into roll templates), you'd only have to edit one set. If you know what fields you are going to be using, you can set up a city template ahead of time, with all the fields in existence. You could even create them with ChatSetAttr. Another advantage to using "selected" is that your attributes have human readable names.

The biggest drawback to this would be if you were going to create hundreds of cities, it might bloat your game a bit.

Thanks so much, I'll work on this and give it a shot.

I've been working on this some more.

Using ChatSetAttr is helping populate the CitySheet's attributes beautifully, thanks for that direction. 

What I would like to do next is use the info so the players can click on locations on the map and get that info.

Using TokenNameNumber I changed CitySheet's default token's name to %%%NUMBERED%%% and dragged 4 on to the map.

Then, using ChatSetAttr I set 1,2,3,4's info up !setattr --name City  --1|info, etc.

Now I want a Macro button to call the correct attribute.

I've gotten this far in the API and I am stuck:

   on("ready",function()
{
    on("chat:message", function(msg){
        if (msg.type=="api" && msg.content.indexOf("!test")==0)
        {
            var selected = msg.selected;
            if (selected ===undefined)
            {
                sendChat("API","Please select a Location");
                return;
            }
            var tok = getObj("graphic",selected[0]._id);
            var tokName = tok.get("name");
            var character = tok.get("represents");
            var charName = ???
            var outputMessage = `&{template:default} {{name=Location Info}} @{${charName}|${tokName}}`; 
            
     sendChat("",outputMessage);
        }
    });     
});        



January 02 (4 years ago)

Edited January 02 (4 years ago)
Oosh
Sheet Author
API Scripter

Since you have the ID, you'd use the same method (geObj) as you did for the token - it's the most efficient way to grab something:

var charId = tok.get('represents'); // I'd change the ambiguous 'character' to 'charId' as this is not the full character object
if (!charId) return sendChat('API', 'Token not linked..'); // This should stop the next getObj from failing on unlinked tokens
var charName = getObj('character', charId).get('name');


I'd avoid using var to define variables with such common names, personally. In a longer script you'd likely have charId used in a number of functions, and having it running free with global scope can lead to issues. It's probably fine for this script if it's only going to be grabbing the same sheet each time it runs, but if you start dealing with multiple functions and sheets, you could avoid some bugs by using let or const instead of var.