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

Changing Layer

April 07 (7 years ago)
MyRoll20Stuffs
API Scripter
Are there commands for changing what layer a token is on?
I want to be able to change 1 token from token layer to GM layer then another token from GM layer to token layer.
I need to do this 6 times on one map and was hoping I could write a macro to do it with a button click instead of manually.
Can anyone help me out with this?
April 07 (7 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
you can either use the tokenmod script (for lots of other powerful features) or enable advanced keyboard shortcuts
April 07 (7 years ago)
The Aaron
Pro
API Scripter
You can use TokenMod:
!token-mod --set layer|map
or keyboard shortcuts:
  • Shift+O: Move selected object to token layer
  • Ctrl/Cmd+Shift+K: Move selected object to GM layer
  • Ctrl/Cmd+Shift+M: Move selected object to map layer
or advanced shortcuts:
Move selected object(s) to Map layerl m
Move selected object(s) to Tokens layerl o
Move selected object(s) to GM layerl k
Move selected object(s) to Dynamic Lighting layerl ,
April 07 (7 years ago)

Edited April 07 (7 years ago)
MyRoll20Stuffs
API Scripter
Okay so I got TokenMod and I basically want to do this:

!token-mod --set layer|gmlayer --ids ID1
!token-mod --set layer|objects --ids ID2

But I have a question. Do tokens that are "None/Generic Token" under "Represents Character" have no token ID? Do you get the token ID from the character sheet? How can I get the token id?

EDIT: I just realized - I probably have to specify map too don't I?
April 07 (7 years ago)

Edited April 07 (7 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
You can call the token_id via @{selected|token_id} or @{target|token_id}. If the two tokens are on different layers to start with then I'm not sure I can think of a way to do it in one macro. Maybe advanced keyboard shortcuts work while in the targeting dialog? and so you could send the macro to chat, target the token that is on your current layer, then use the advanced keyboard shortcut to change to the other layer and then target the second token?

Edit, what are you attempting to do with this macro? As in what game issue are you trying to solve?
April 07 (7 years ago)
MyRoll20Stuffs
API Scripter
I made a quick macro button to do this:

/w gm @{selected|token_id}

Then got the IDs and did this in my other macro:

!token-mod --set layer|gmlayer --ids -L8pYdCPs-vXAXXnIazI
!token-mod --set layer|objects --ids -L8pVXqjY5rMB1_2EyEK

I'm trying to hide a corpse and make a zombie visible, and I need to do this 6 times to 6 corpses and 6 zombies so I'm going to have a GM button called C2Z which switched the layers of the 12 tokens then Z2C to revert them back to corpses
April 07 (7 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Ah, the better way might be to make rollable table tokens and then use token mod to simply switch the side that is shown.
April 07 (7 years ago)
MyRoll20Stuffs
API Scripter

Scott C. said:

Ah, the better way might be to make rollable table tokens and then use token mod to simply switch the side that is shown.

Can you go into detail how this is done? I already finished it my way but curious if this might be the better approach and want more information.
April 07 (7 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Type 
!token-mod --help
into the chat window. It will give you a very good overview of the power of this essential script, including how to change faces. Though you may want to pop the chat window out and widen it for easier reading. 

As for rollable table tokens (which would do exactly what you want) look here.

April 07 (7 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Thanks for that Keith. I don't use tokenmod much, so I'm not great at explaining how to do things with it.
April 07 (7 years ago)
MyRoll20Stuffs
API Scripter
While rollable tables look very cool, I don't think it's the right approach for what I need. I have various ambush encounters not just with zombies and having a button I can click to run a macro to move ALL the tokens from gmlayer to objects layer in one click seems better suited to my needs.

One problem that comes to mind is I show health bars of all NPCs to my players. The corpse doesn't have a health bar. The zombie does. Rollable table functionality would show the corpse with a health bar. I'd have to write whole new macros to fill out bar1 when the side is changed from corpse to zombie. I'll probably use rollable tables for other things in the future like randomizing the token art but I don't think it's the right fit for me for the functionality I want.
April 07 (7 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Ah, yes, that would cause an issue.
April 07 (7 years ago)

Edited April 07 (7 years ago)
MyRoll20Stuffs
API Scripter
I read somewhere about being able to mirror tokens but that seems to be mirroring one pages movement of a token on another page.

Is there a way for me to "sticky" one token to another (the corpse token to the zombie token) so when i move the zombie token on the object layer, the corpse token moves with it on the gmlayer? I want to be able to revert the zombie back to a corpse when it's killed and be in the same position on the map as the zombie was and move zombie back to gmlayer and corpse to object layer.

EDIT:
This gave me an idea of how to do this but I need some help.
Can you do IF statements in a macro?
And can you move the position of a token with a macro?

I basically want to do this:

if (zombie-hp < 1)
get zombie-position
move corpse zombie-position
set zombie layer|gmlayer
set corpse layer|objects
April 07 (7 years ago)
MyRoll20Stuffs
API Scripter
I'm stuck on one part of this. How do you reference a token by it's id? I mean I try something like

@{-L8pcQGI8pKS4fXiJzD|token_id|HP}
or
@{token_id|-L8pcQGI8pKS4fXiJzD|HP}

So how do I reference a token's stats when I know the ID of the token?
April 07 (7 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
You could try:
@{-L8pcQGI8pKS4fXiJzD|bar1}

Tokens don't have attributes. To reference an attribute, you have to reference a character.
April 07 (7 years ago)
MyRoll20Stuffs
API Scripter

Scott C. said:

You could try:
@{-L8pcQGI8pKS4fXiJzD|bar1}

Tokens don't have attributes. To reference an attribute, you have to reference a character.

Doesn't seem to work. Maybe I can do @{character_id|HP} if I know that tokens character ID?
Where on the Pathfinder Community Sheet can I find that sheets ID?
April 07 (7 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
You can do @{Character Name|character_id} to get the character id of a character sheet. Or you can do @{Character Name|HP} to get the character's hp.
April 07 (7 years ago)
MyRoll20Stuffs
API Scripter
@{Character Name|HP} works that did the trick.

So I have this:
[[{{@{Burnt Zombie 2|HP},0}>1}*(F-T) + T]]

Which outputs 1 if the zombie has more than 0 HP, and 0 if it has < 1 HP.

Now this is the part where it gets complicated. How do I now do a set of instructions if the result is 0. What do I have to wrap this in to accomplish that? 

Another question: What's the macro command to get a token's X/Y position on the map, and how do you set a token's X/Y position on the map to move it using a macro?
April 07 (7 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator

Kastion said:

@{Character Name|HP} works that did the trick.

So I have this:
[[{{@{Burnt Zombie 2|HP},0}>1}*(F-T) + T]]

Which outputs 1 if the zombie has more than 0 HP, and 0 if it has < 1 HP.

Now this is the part where it gets complicated. How do I now do a set of instructions if the result is 0. What do I have to wrap this in to accomplish that? 
Not possible without a separate API script
Another question: What's the macro command to get a token's X/Y position on the map, and how do you set a token's X/Y position on the map to move it using a macro?
Also not possible without a separate API script

April 07 (7 years ago)
MyRoll20Stuffs
API Scripter
Okay so I found a script to move tokens:
https://wiki.roll20.net/Script:Slide_Tokens

Is it possible to get the values of a tokens X/Y natively or do I need a script for that too? Does TokenMod have an option to get the token's X/Y I haven't read all the help yet so I'm not sure.
April 07 (7 years ago)
MyRoll20Stuffs
API Scripter
Slide Tokens didn't work for me I couldn't get the script to work there were errors in the API Sandbox
But I did find out you can move tokens with !token-mod

!token-mod --set top|[[70*10]] left|[[70*10]] --ids -L8pWFs3MI1asfUPcMEK

So now I need one more element to get this to work.

Is there a way to get the X/Y of a token? maybe a "!token-mod --get" or something? Or built in native values you can get off of a targeted token?
April 07 (7 years ago)
MyRoll20Stuffs
API Scripter
So I'm using this script to store the position of the zombie:
on('ready', function(){
    "use strict";


    on('change:graphic',function(obj,prev){
        if( ( _.contains(['gmlayer','objects'],obj.get('layer')) ) &&
            ( obj.get('left') !== prev.left || obj.get('top') !== prev.top) &&
            obj.get('represents') ) {
            let a=_.chain(findObjs({type: 'attribute',characterid: obj.get('represents')}))
                    .filter(a=>a.get('name').match(/^position-[xy]$/))
                    .each(a=>{
                        switch(a.get('name')){
                            case 'position-x': 
                                a.set({current: obj.get('left')});
                                break;
                            case 'position-y': 
                                a.set({current: obj.get('top')});
                                break;
                        }
                    });
        }
    });
});


And moving the corpse to them like this:

!token-mod --set top|[[@{Burnt Zombie 5|position-y}]] left|[[@{Burnt Zombie 5|position-x}]] --ids -L8pWFs3MI1asfUPcMEK

Now all I need to finish what I'm trying to accomplish is a way to do conditional statements.

if (zombie-hp < 1)
	move corpse to zombie X/Y
	move zombie to gm layer
	move corpse to object layer

Anyone know of any scripts that will allow me to do conditional statements?
April 07 (7 years ago)
The Aaron
Pro
API Scripter
Wow!  Just got back from visiting my bro and I'm catching up.

I think I would suggest using TokenMod and a Rollable Table Token, then just have part of the TokenMod command flip the visibility on the bar.  Assuming You're using bar1 for health:
!token-mod {{
  --flip showplayers_bar1
  --set currentside|+1
}}
Just select the corpses and hit that macro and they will all switch to the next image (wrapping back to the beginning) and show their bars.  Select the zombie that dies and hit that macro and it will go back to the corpse (assuming 2 images in the token) and hide the bar.


April 07 (7 years ago)
MyRoll20Stuffs
API Scripter
Okay so I have a table made with 2 entries. A corpse and a zombie.
It starts as a zombie with the health bar visible then I run this:
!token-mod {{
  --flip showplayers_bar1
  --set currentside|+1
  --ids -L9XAPZ37vev6CtDzGUN
}}
And it turns it into a corpse and hides the healthbar.

But when I run it again, it toggles health bar, but doesn't turn back into a zombie.
April 07 (7 years ago)
MyRoll20Stuffs
API Scripter
For some reason running that token mod command isn't changing the currentside at all...
April 07 (7 years ago)
The Aaron
Pro
API Scripter
hmm.. if you want to send me an invite, I can come take a look.  It's working in my test campaign, maybe something got broken though.
April 07 (7 years ago)
MyRoll20Stuffs
API Scripter

The Aaron said:

hmm.. if you want to send me an invite, I can come take a look.  It's working in my test campaign, maybe something got broken though.

PM'd you a link
April 08 (7 years ago)
MyRoll20Stuffs
API Scripter
The Aaron hopped in my game and we got this resolved.
The image I was using for the zombie was from the marketplace and not in my library so that was causing issues with the table rolling and swapping out sprites.

Thanks a lot The Aaron for your help! I was making this more complicated than it had to be now I know how powerful token-mod really is.
April 08 (7 years ago)
The Aaron
Pro
API Scripter
=D no worries!
April 08 (7 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Token-mod is so versatile, that the Swiss army has just adopted it as a replacement for their knives. Token-mod is both a floor wax and a dessert topping. It means both hello and good bye. Eskimos have replaced all uses of the word "snow, with "token-mod". When in your terminal, you can type token-mod, instead of sudo. Token-mod can also be used in place of the Konami code, and is projected to replace "swordfish" as the default password chosen by all hackers in Hollywood movies.
April 08 (7 years ago)

Edited April 08 (7 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
hahaha. Only thing you forgot was:

All hail our lord and master, The Arcane Scriptomancer Aaron. Long may he code.
April 08 (7 years ago)
The Aaron
Pro
API Scripter
HAHAHAHAHAHAHA.

adding alias token-mod=sudo to my .zshrc...  =D